#importing all the necessary libraries
import pandas as pd
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
from sklearn.preprocessing import LabelEncoder
from sklearn.metrics import mean_absolute_error
from sklearn.model_selection import train_test_split
from sklearn import svm
from sklearn.svm import SVC
from sklearn.metrics import mean_absolute_percentage_error
from sklearn.preprocessing import RobustScaler, MinMaxScaler
import sweetviz as sv
import warnings
from sklearn.feature_selection import VarianceThreshold
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import RobustScaler, MinMaxScaler
from sklearn.model_selection import GridSearchCV
from sklearn.linear_model import Ridge
from sklearn.linear_model import Lasso
from sklearn.preprocessing import OneHotEncoder
from sklearn.metrics import r2_score
from sklearn.metrics import mean_squared_error
from sklearn.metrics import mean_absolute_error
from sklearn.neighbors import KNeighborsRegressor
from sklearn.model_selection import GridSearchCV
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import GradientBoostingRegressor
df = pd.read_csv(r"C:\Users\HP\Downloads\train.csv")
print("Full train dataset shape is {}".format(df.shape))
df_org = df.copy()
Full train dataset shape is (1460, 81)
df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 1460 entries, 0 to 1459 Data columns (total 81 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Id 1460 non-null int64 1 MSSubClass 1460 non-null int64 2 MSZoning 1460 non-null object 3 LotFrontage 1201 non-null float64 4 LotArea 1460 non-null int64 5 Street 1460 non-null object 6 Alley 91 non-null object 7 LotShape 1460 non-null object 8 LandContour 1460 non-null object 9 Utilities 1460 non-null object 10 LotConfig 1460 non-null object 11 LandSlope 1460 non-null object 12 Neighborhood 1460 non-null object 13 Condition1 1460 non-null object 14 Condition2 1460 non-null object 15 BldgType 1460 non-null object 16 HouseStyle 1460 non-null object 17 OverallQual 1460 non-null int64 18 OverallCond 1460 non-null int64 19 YearBuilt 1460 non-null int64 20 YearRemodAdd 1460 non-null int64 21 RoofStyle 1460 non-null object 22 RoofMatl 1460 non-null object 23 Exterior1st 1460 non-null object 24 Exterior2nd 1460 non-null object 25 MasVnrType 1452 non-null object 26 MasVnrArea 1452 non-null float64 27 ExterQual 1460 non-null object 28 ExterCond 1460 non-null object 29 Foundation 1460 non-null object 30 BsmtQual 1423 non-null object 31 BsmtCond 1423 non-null object 32 BsmtExposure 1422 non-null object 33 BsmtFinType1 1423 non-null object 34 BsmtFinSF1 1460 non-null int64 35 BsmtFinType2 1422 non-null object 36 BsmtFinSF2 1460 non-null int64 37 BsmtUnfSF 1460 non-null int64 38 TotalBsmtSF 1460 non-null int64 39 Heating 1460 non-null object 40 HeatingQC 1460 non-null object 41 CentralAir 1460 non-null object 42 Electrical 1459 non-null object 43 1stFlrSF 1460 non-null int64 44 2ndFlrSF 1460 non-null int64 45 LowQualFinSF 1460 non-null int64 46 GrLivArea 1460 non-null int64 47 BsmtFullBath 1460 non-null int64 48 BsmtHalfBath 1460 non-null int64 49 FullBath 1460 non-null int64 50 HalfBath 1460 non-null int64 51 BedroomAbvGr 1460 non-null int64 52 KitchenAbvGr 1460 non-null int64 53 KitchenQual 1460 non-null object 54 TotRmsAbvGrd 1460 non-null int64 55 Functional 1460 non-null object 56 Fireplaces 1460 non-null int64 57 FireplaceQu 770 non-null object 58 GarageType 1379 non-null object 59 GarageYrBlt 1379 non-null float64 60 GarageFinish 1379 non-null object 61 GarageCars 1460 non-null int64 62 GarageArea 1460 non-null int64 63 GarageQual 1379 non-null object 64 GarageCond 1379 non-null object 65 PavedDrive 1460 non-null object 66 WoodDeckSF 1460 non-null int64 67 OpenPorchSF 1460 non-null int64 68 EnclosedPorch 1460 non-null int64 69 3SsnPorch 1460 non-null int64 70 ScreenPorch 1460 non-null int64 71 PoolArea 1460 non-null int64 72 PoolQC 7 non-null object 73 Fence 281 non-null object 74 MiscFeature 54 non-null object 75 MiscVal 1460 non-null int64 76 MoSold 1460 non-null int64 77 YrSold 1460 non-null int64 78 SaleType 1460 non-null object 79 SaleCondition 1460 non-null object 80 SalePrice 1460 non-null int64 dtypes: float64(3), int64(35), object(43) memory usage: 924.0+ KB
df.isnull()
| Id | MSSubClass | MSZoning | LotFrontage | LotArea | Street | Alley | LotShape | LandContour | Utilities | ... | PoolArea | PoolQC | Fence | MiscFeature | MiscVal | MoSold | YrSold | SaleType | SaleCondition | SalePrice | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | False | False | False | False | False | False | True | False | False | False | ... | False | True | True | True | False | False | False | False | False | False |
| 1 | False | False | False | False | False | False | True | False | False | False | ... | False | True | True | True | False | False | False | False | False | False |
| 2 | False | False | False | False | False | False | True | False | False | False | ... | False | True | True | True | False | False | False | False | False | False |
| 3 | False | False | False | False | False | False | True | False | False | False | ... | False | True | True | True | False | False | False | False | False | False |
| 4 | False | False | False | False | False | False | True | False | False | False | ... | False | True | True | True | False | False | False | False | False | False |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 1455 | False | False | False | False | False | False | True | False | False | False | ... | False | True | True | True | False | False | False | False | False | False |
| 1456 | False | False | False | False | False | False | True | False | False | False | ... | False | True | False | True | False | False | False | False | False | False |
| 1457 | False | False | False | False | False | False | True | False | False | False | ... | False | True | False | False | False | False | False | False | False | False |
| 1458 | False | False | False | False | False | False | True | False | False | False | ... | False | True | True | True | False | False | False | False | False | False |
| 1459 | False | False | False | False | False | False | True | False | False | False | ... | False | True | True | True | False | False | False | False | False | False |
1460 rows × 81 columns
# Checking descriptive statistics
df.describe().T
| count | mean | std | min | 25% | 50% | 75% | max | |
|---|---|---|---|---|---|---|---|---|
| Id | 1460.0 | 730.500000 | 421.610009 | 1.0 | 365.75 | 730.5 | 1095.25 | 1460.0 |
| MSSubClass | 1460.0 | 56.897260 | 42.300571 | 20.0 | 20.00 | 50.0 | 70.00 | 190.0 |
| LotFrontage | 1201.0 | 70.049958 | 24.284752 | 21.0 | 59.00 | 69.0 | 80.00 | 313.0 |
| LotArea | 1460.0 | 10516.828082 | 9981.264932 | 1300.0 | 7553.50 | 9478.5 | 11601.50 | 215245.0 |
| OverallQual | 1460.0 | 6.099315 | 1.382997 | 1.0 | 5.00 | 6.0 | 7.00 | 10.0 |
| OverallCond | 1460.0 | 5.575342 | 1.112799 | 1.0 | 5.00 | 5.0 | 6.00 | 9.0 |
| YearBuilt | 1460.0 | 1971.267808 | 30.202904 | 1872.0 | 1954.00 | 1973.0 | 2000.00 | 2010.0 |
| YearRemodAdd | 1460.0 | 1984.865753 | 20.645407 | 1950.0 | 1967.00 | 1994.0 | 2004.00 | 2010.0 |
| MasVnrArea | 1452.0 | 103.685262 | 181.066207 | 0.0 | 0.00 | 0.0 | 166.00 | 1600.0 |
| BsmtFinSF1 | 1460.0 | 443.639726 | 456.098091 | 0.0 | 0.00 | 383.5 | 712.25 | 5644.0 |
| BsmtFinSF2 | 1460.0 | 46.549315 | 161.319273 | 0.0 | 0.00 | 0.0 | 0.00 | 1474.0 |
| BsmtUnfSF | 1460.0 | 567.240411 | 441.866955 | 0.0 | 223.00 | 477.5 | 808.00 | 2336.0 |
| TotalBsmtSF | 1460.0 | 1057.429452 | 438.705324 | 0.0 | 795.75 | 991.5 | 1298.25 | 6110.0 |
| 1stFlrSF | 1460.0 | 1162.626712 | 386.587738 | 334.0 | 882.00 | 1087.0 | 1391.25 | 4692.0 |
| 2ndFlrSF | 1460.0 | 346.992466 | 436.528436 | 0.0 | 0.00 | 0.0 | 728.00 | 2065.0 |
| LowQualFinSF | 1460.0 | 5.844521 | 48.623081 | 0.0 | 0.00 | 0.0 | 0.00 | 572.0 |
| GrLivArea | 1460.0 | 1515.463699 | 525.480383 | 334.0 | 1129.50 | 1464.0 | 1776.75 | 5642.0 |
| BsmtFullBath | 1460.0 | 0.425342 | 0.518911 | 0.0 | 0.00 | 0.0 | 1.00 | 3.0 |
| BsmtHalfBath | 1460.0 | 0.057534 | 0.238753 | 0.0 | 0.00 | 0.0 | 0.00 | 2.0 |
| FullBath | 1460.0 | 1.565068 | 0.550916 | 0.0 | 1.00 | 2.0 | 2.00 | 3.0 |
| HalfBath | 1460.0 | 0.382877 | 0.502885 | 0.0 | 0.00 | 0.0 | 1.00 | 2.0 |
| BedroomAbvGr | 1460.0 | 2.866438 | 0.815778 | 0.0 | 2.00 | 3.0 | 3.00 | 8.0 |
| KitchenAbvGr | 1460.0 | 1.046575 | 0.220338 | 0.0 | 1.00 | 1.0 | 1.00 | 3.0 |
| TotRmsAbvGrd | 1460.0 | 6.517808 | 1.625393 | 2.0 | 5.00 | 6.0 | 7.00 | 14.0 |
| Fireplaces | 1460.0 | 0.613014 | 0.644666 | 0.0 | 0.00 | 1.0 | 1.00 | 3.0 |
| GarageYrBlt | 1379.0 | 1978.506164 | 24.689725 | 1900.0 | 1961.00 | 1980.0 | 2002.00 | 2010.0 |
| GarageCars | 1460.0 | 1.767123 | 0.747315 | 0.0 | 1.00 | 2.0 | 2.00 | 4.0 |
| GarageArea | 1460.0 | 472.980137 | 213.804841 | 0.0 | 334.50 | 480.0 | 576.00 | 1418.0 |
| WoodDeckSF | 1460.0 | 94.244521 | 125.338794 | 0.0 | 0.00 | 0.0 | 168.00 | 857.0 |
| OpenPorchSF | 1460.0 | 46.660274 | 66.256028 | 0.0 | 0.00 | 25.0 | 68.00 | 547.0 |
| EnclosedPorch | 1460.0 | 21.954110 | 61.119149 | 0.0 | 0.00 | 0.0 | 0.00 | 552.0 |
| 3SsnPorch | 1460.0 | 3.409589 | 29.317331 | 0.0 | 0.00 | 0.0 | 0.00 | 508.0 |
| ScreenPorch | 1460.0 | 15.060959 | 55.757415 | 0.0 | 0.00 | 0.0 | 0.00 | 480.0 |
| PoolArea | 1460.0 | 2.758904 | 40.177307 | 0.0 | 0.00 | 0.0 | 0.00 | 738.0 |
| MiscVal | 1460.0 | 43.489041 | 496.123024 | 0.0 | 0.00 | 0.0 | 0.00 | 15500.0 |
| MoSold | 1460.0 | 6.321918 | 2.703626 | 1.0 | 5.00 | 6.0 | 8.00 | 12.0 |
| YrSold | 1460.0 | 2007.815753 | 1.328095 | 2006.0 | 2007.00 | 2008.0 | 2009.00 | 2010.0 |
| SalePrice | 1460.0 | 180921.195890 | 79442.502883 | 34900.0 | 129975.00 | 163000.0 | 214000.00 | 755000.0 |
## Checking percentage of missing values
missing_info= round(df.isna().sum() * 100/df.shape[0], 2)
missing_info[missing_info > 0].sort_values(ascending= False)
PoolQC 99.52 MiscFeature 96.30 Alley 93.77 Fence 80.75 FireplaceQu 47.26 LotFrontage 17.74 GarageType 5.55 GarageYrBlt 5.55 GarageFinish 5.55 GarageQual 5.55 GarageCond 5.55 BsmtExposure 2.60 BsmtFinType2 2.60 BsmtFinType1 2.53 BsmtCond 2.53 BsmtQual 2.53 MasVnrArea 0.55 MasVnrType 0.55 Electrical 0.07 dtype: float64
# Getting column names having missing values
missing_val_cols= missing_info[missing_info > 0].sort_values(ascending= False).index
missing_val_cols
Index(['PoolQC', 'MiscFeature', 'Alley', 'Fence', 'FireplaceQu', 'LotFrontage',
'GarageType', 'GarageYrBlt', 'GarageFinish', 'GarageQual', 'GarageCond',
'BsmtExposure', 'BsmtFinType2', 'BsmtFinType1', 'BsmtCond', 'BsmtQual',
'MasVnrArea', 'MasVnrType', 'Electrical'],
dtype='object')
# Checking unique values in these columns
for col in missing_val_cols:
print('\nColumn Name:',col)
print(df[col].value_counts(dropna= False))
Column Name: PoolQC
NaN 1453
Gd 3
Ex 2
Fa 2
Name: PoolQC, dtype: int64
Column Name: MiscFeature
NaN 1406
Shed 49
Gar2 2
Othr 2
TenC 1
Name: MiscFeature, dtype: int64
Column Name: Alley
NaN 1369
Grvl 50
Pave 41
Name: Alley, dtype: int64
Column Name: Fence
NaN 1179
MnPrv 157
GdPrv 59
GdWo 54
MnWw 11
Name: Fence, dtype: int64
Column Name: FireplaceQu
NaN 690
Gd 380
TA 313
Fa 33
Ex 24
Po 20
Name: FireplaceQu, dtype: int64
Column Name: LotFrontage
NaN 259
60.0 143
70.0 70
80.0 69
50.0 57
...
137.0 1
38.0 1
33.0 1
150.0 1
46.0 1
Name: LotFrontage, Length: 111, dtype: int64
Column Name: GarageType
Attchd 870
Detchd 387
BuiltIn 88
NaN 81
Basment 19
CarPort 9
2Types 6
Name: GarageType, dtype: int64
Column Name: GarageYrBlt
NaN 81
2005.0 65
2006.0 59
2004.0 53
2003.0 50
..
1927.0 1
1900.0 1
1906.0 1
1908.0 1
1933.0 1
Name: GarageYrBlt, Length: 98, dtype: int64
Column Name: GarageFinish
Unf 605
RFn 422
Fin 352
NaN 81
Name: GarageFinish, dtype: int64
Column Name: GarageQual
TA 1311
NaN 81
Fa 48
Gd 14
Ex 3
Po 3
Name: GarageQual, dtype: int64
Column Name: GarageCond
TA 1326
NaN 81
Fa 35
Gd 9
Po 7
Ex 2
Name: GarageCond, dtype: int64
Column Name: BsmtExposure
No 953
Av 221
Gd 134
Mn 114
NaN 38
Name: BsmtExposure, dtype: int64
Column Name: BsmtFinType2
Unf 1256
Rec 54
LwQ 46
NaN 38
BLQ 33
ALQ 19
GLQ 14
Name: BsmtFinType2, dtype: int64
Column Name: BsmtFinType1
Unf 430
GLQ 418
ALQ 220
BLQ 148
Rec 133
LwQ 74
NaN 37
Name: BsmtFinType1, dtype: int64
Column Name: BsmtCond
TA 1311
Gd 65
Fa 45
NaN 37
Po 2
Name: BsmtCond, dtype: int64
Column Name: BsmtQual
TA 649
Gd 618
Ex 121
NaN 37
Fa 35
Name: BsmtQual, dtype: int64
Column Name: MasVnrArea
0.0 861
NaN 8
72.0 8
108.0 8
180.0 8
...
562.0 1
89.0 1
921.0 1
762.0 1
119.0 1
Name: MasVnrArea, Length: 328, dtype: int64
Column Name: MasVnrType
None 864
BrkFace 445
Stone 128
BrkCmn 15
NaN 8
Name: MasVnrType, dtype: int64
Column Name: Electrical
SBrkr 1334
FuseA 94
FuseF 27
FuseP 3
Mix 1
NaN 1
Name: Electrical, dtype: int64
# Replacing NaN with 'Not Present' for below columns
valid_nan_cols= ['PoolQC', 'MiscFeature', 'Alley', 'Fence', 'FireplaceQu', 'GarageType', 'GarageFinish', 'GarageQual', 'GarageCond', 'BsmtFinType2', 'BsmtExposure', 'BsmtFinType1', 'BsmtCond', 'BsmtQual']
df[valid_nan_cols]= df[valid_nan_cols].fillna('Not Present')
# Checking percentage of missing values again
missing_info= round(df.isna().sum() * 100/df.shape[0], 2)
missing_info[missing_info > 0].sort_values(ascending= False)
LotFrontage 17.74 GarageYrBlt 5.55 MasVnrType 0.55 MasVnrArea 0.55 Electrical 0.07 dtype: float64
# Checking if there is any relation between GarageYrBlt and GarageType
df[df.GarageYrBlt.isna()]['GarageType'].value_counts(normalize= True)
Not Present 1.0 Name: GarageType, dtype: float64
There are a total of 19 columns with missing values. Notably, PoolQC, MiscFeature, Alley, Fence, and FireplaceQu exhibit a particularly high percentage of missing values. It is crucial to examine these columns individually to determine whether these missing values are indeed indicative of actual data gaps or if they hold some meaningful information. Once we identify the nature of these missing values, we can proceed with the appropriate imputation technique. One approach is to utilize business knowledge for imputation, where NaN values can be replaced with values derived from relevant business logic. Alternatively, statistical imputation methods can be employed after performing a train-test split, allowing missing values to be filled based on statistical techniques.
# Getting column names having missing values
missing_val_cols= missing_info[missing_info > 0].sort_values(ascending= False).index
missing_val_cols
Index(['LotFrontage', 'GarageYrBlt', 'MasVnrType', 'MasVnrArea', 'Electrical'], dtype='object')
# Checking unique values in these columns
for col in missing_val_cols:
print('\nColumn Name:',col)
print(df[col].value_counts(dropna= False))
Column Name: LotFrontage
NaN 259
60.0 143
70.0 70
80.0 69
50.0 57
...
137.0 1
38.0 1
33.0 1
150.0 1
46.0 1
Name: LotFrontage, Length: 111, dtype: int64
Column Name: GarageYrBlt
NaN 81
2005.0 65
2006.0 59
2004.0 53
2003.0 50
..
1927.0 1
1900.0 1
1906.0 1
1908.0 1
1933.0 1
Name: GarageYrBlt, Length: 98, dtype: int64
Column Name: MasVnrType
None 864
BrkFace 445
Stone 128
BrkCmn 15
NaN 8
Name: MasVnrType, dtype: int64
Column Name: MasVnrArea
0.0 861
NaN 8
72.0 8
108.0 8
180.0 8
...
562.0 1
89.0 1
921.0 1
762.0 1
119.0 1
Name: MasVnrArea, Length: 328, dtype: int64
Column Name: Electrical
SBrkr 1334
FuseA 94
FuseF 27
FuseP 3
Mix 1
NaN 1
Name: Electrical, dtype: int64
# Replacing NaN with 'Not Present' for below columns
valid_nan_cols= ['PoolQC', 'MiscFeature', 'Alley', 'Fence', 'FireplaceQu', 'GarageType', 'GarageFinish', 'GarageQual', 'GarageCond', 'BsmtFinType2', 'BsmtExposure', 'BsmtFinType1', 'BsmtCond', 'BsmtQual']
df[valid_nan_cols]= df[valid_nan_cols].fillna('Not Present')
# Checking percentage of missing values again
missing_info= round(df.isna().sum() * 100/df.shape[0], 2)
missing_info[missing_info > 0].sort_values(ascending= False)
LotFrontage 17.74 GarageYrBlt 5.55 MasVnrType 0.55 MasVnrArea 0.55 Electrical 0.07 dtype: float64
# Checking if there is any relation between GarageYrBlt and GarageType
df[df.GarageYrBlt.isna()]['GarageType'].value_counts(normalize= True)
Not Present 1.0 Name: GarageType, dtype: float64
Initially, both GarageYrBlt and GarageType had a missing value percentage of 5.55%. However, after replacing the NaN values of GarageType with 'Not Available', we observed that the GarageYrBlt values were only NaN for those instances where GarageType was labeled as 'Not Available'. This indicates that if a garage is not available, there will be no corresponding value for 'GarageYrBlt'. As a result, it is reasonable to safely replace the NaN values of GarageYrBlt with 0.
# Imputing missing values of GarageYrBlt column
df['GarageYrBlt']= df['GarageYrBlt'].fillna(0)
# Changing data type of MSSubClass. MSSubClass: "identifies the type of dwelling involved in the sale",
#is a categorical variable, but it's appearing as a numeric variable.
df['MSSubClass']= df['MSSubClass'].astype('object')
df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 1460 entries, 0 to 1459 Data columns (total 81 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Id 1460 non-null int64 1 MSSubClass 1460 non-null object 2 MSZoning 1460 non-null object 3 LotFrontage 1201 non-null float64 4 LotArea 1460 non-null int64 5 Street 1460 non-null object 6 Alley 1460 non-null object 7 LotShape 1460 non-null object 8 LandContour 1460 non-null object 9 Utilities 1460 non-null object 10 LotConfig 1460 non-null object 11 LandSlope 1460 non-null object 12 Neighborhood 1460 non-null object 13 Condition1 1460 non-null object 14 Condition2 1460 non-null object 15 BldgType 1460 non-null object 16 HouseStyle 1460 non-null object 17 OverallQual 1460 non-null int64 18 OverallCond 1460 non-null int64 19 YearBuilt 1460 non-null int64 20 YearRemodAdd 1460 non-null int64 21 RoofStyle 1460 non-null object 22 RoofMatl 1460 non-null object 23 Exterior1st 1460 non-null object 24 Exterior2nd 1460 non-null object 25 MasVnrType 1452 non-null object 26 MasVnrArea 1452 non-null float64 27 ExterQual 1460 non-null object 28 ExterCond 1460 non-null object 29 Foundation 1460 non-null object 30 BsmtQual 1460 non-null object 31 BsmtCond 1460 non-null object 32 BsmtExposure 1460 non-null object 33 BsmtFinType1 1460 non-null object 34 BsmtFinSF1 1460 non-null int64 35 BsmtFinType2 1460 non-null object 36 BsmtFinSF2 1460 non-null int64 37 BsmtUnfSF 1460 non-null int64 38 TotalBsmtSF 1460 non-null int64 39 Heating 1460 non-null object 40 HeatingQC 1460 non-null object 41 CentralAir 1460 non-null object 42 Electrical 1459 non-null object 43 1stFlrSF 1460 non-null int64 44 2ndFlrSF 1460 non-null int64 45 LowQualFinSF 1460 non-null int64 46 GrLivArea 1460 non-null int64 47 BsmtFullBath 1460 non-null int64 48 BsmtHalfBath 1460 non-null int64 49 FullBath 1460 non-null int64 50 HalfBath 1460 non-null int64 51 BedroomAbvGr 1460 non-null int64 52 KitchenAbvGr 1460 non-null int64 53 KitchenQual 1460 non-null object 54 TotRmsAbvGrd 1460 non-null int64 55 Functional 1460 non-null object 56 Fireplaces 1460 non-null int64 57 FireplaceQu 1460 non-null object 58 GarageType 1460 non-null object 59 GarageYrBlt 1460 non-null float64 60 GarageFinish 1460 non-null object 61 GarageCars 1460 non-null int64 62 GarageArea 1460 non-null int64 63 GarageQual 1460 non-null object 64 GarageCond 1460 non-null object 65 PavedDrive 1460 non-null object 66 WoodDeckSF 1460 non-null int64 67 OpenPorchSF 1460 non-null int64 68 EnclosedPorch 1460 non-null int64 69 3SsnPorch 1460 non-null int64 70 ScreenPorch 1460 non-null int64 71 PoolArea 1460 non-null int64 72 PoolQC 1460 non-null object 73 Fence 1460 non-null object 74 MiscFeature 1460 non-null object 75 MiscVal 1460 non-null int64 76 MoSold 1460 non-null int64 77 YrSold 1460 non-null int64 78 SaleType 1460 non-null object 79 SaleCondition 1460 non-null object 80 SalePrice 1460 non-null int64 dtypes: float64(3), int64(34), object(44) memory usage: 924.0+ KB
# Running SweetViz AutoEDA
sv_report= sv.analyze(df)
sv_report.show_notebook()
| | [ 0%] 00:00 ->…
# Plotting numeric variables against SalePrice
numeric_cols= ['GrLivArea','GarageArea','TotalBsmtSF','1stFlrSF','TotRmsAbvGrd','YearBuilt','YearRemodAdd','MasVnrArea',
'BsmtFinSF1','LotFrontage','WoodDeckSF','2ndFlrSF','OpenPorchSF','LotArea']
sns.pairplot(df, x_vars=['GrLivArea','GarageArea','TotalBsmtSF','1stFlrSF','TotRmsAbvGrd'], y_vars='SalePrice', kind= 'reg', plot_kws={'line_kws':{'color':'teal'}})
sns.pairplot(df, x_vars=['YearBuilt','YearRemodAdd','MasVnrArea','BsmtFinSF1','LotFrontage'], y_vars='SalePrice', kind= 'reg', plot_kws={'line_kws':{'color':'teal'}})
sns.pairplot(df, x_vars=['WoodDeckSF','2ndFlrSF','OpenPorchSF','LotArea'], y_vars='SalePrice', kind= 'reg', plot_kws={'line_kws':{'color':'teal'}})
<seaborn.axisgrid.PairGrid at 0x2d60ae79b40>
# Box plot of catego
cat_cols= ['OverallQual','GarageCars','ExterQual','BsmtQual','KitchenQual','FullBath','GarageFinish','FireplaceQu','Foundation','GarageType','Fireplaces','BsmtFinType1','HeatingQC']
plt.figure(figsize=[18, 40])
for i, col in enumerate(cat_cols, 1):
plt.subplot(7,2,i)
title_text= f'Box plot {col} vs cnt'
x_label= f'{col}'
fig= sns.boxplot(data= df, x= col, y= 'SalePrice', palette= 'Greens')
fig.set_title(title_text, fontdict= { 'fontsize': 18, 'color': 'Green'})
fig.set_xlabel(x_label, fontdict= {'fontsize': 12, 'color': 'Brown'})
plt.show()
plt.figure(figsize=[17,7])
sns.boxplot(data= df, x= 'Neighborhood', y= 'SalePrice', palette= 'Greens')
plt.show()
plt.figure(figsize=(24, 12))
sns.heatmap(df.corr(),
cmap = 'BrBG',
fmt = '.2f',
linewidths = 2,
annot = True)
C:\Users\HP\AppData\Local\Temp\ipykernel_11432\813657993.py:2: FutureWarning: The default value of numeric_only in DataFrame.corr is deprecated. In a future version, it will default to False. Select only valid columns or specify the value of numeric_only to silence this warning. sns.heatmap(df.corr(),
<Axes: >
obj = (df.dtypes == 'object')
object_cols = list(obj[obj].index)
print("Categorical variables:",len(object_cols))
int_ = (df.dtypes == 'int')
num_cols = list(int_[int_].index)
print("Integer variables:",len(num_cols))
fl = (df.dtypes == 'float')
fl_cols = list(fl[fl].index)
print("Float variables:",len(fl_cols))
Categorical variables: 44 Integer variables: 0 Float variables: 3
df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 1460 entries, 0 to 1459 Data columns (total 81 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Id 1460 non-null int64 1 MSSubClass 1460 non-null object 2 MSZoning 1460 non-null object 3 LotFrontage 1201 non-null float64 4 LotArea 1460 non-null int64 5 Street 1460 non-null object 6 Alley 1460 non-null object 7 LotShape 1460 non-null object 8 LandContour 1460 non-null object 9 Utilities 1460 non-null object 10 LotConfig 1460 non-null object 11 LandSlope 1460 non-null object 12 Neighborhood 1460 non-null object 13 Condition1 1460 non-null object 14 Condition2 1460 non-null object 15 BldgType 1460 non-null object 16 HouseStyle 1460 non-null object 17 OverallQual 1460 non-null int64 18 OverallCond 1460 non-null int64 19 YearBuilt 1460 non-null int64 20 YearRemodAdd 1460 non-null int64 21 RoofStyle 1460 non-null object 22 RoofMatl 1460 non-null object 23 Exterior1st 1460 non-null object 24 Exterior2nd 1460 non-null object 25 MasVnrType 1452 non-null object 26 MasVnrArea 1452 non-null float64 27 ExterQual 1460 non-null object 28 ExterCond 1460 non-null object 29 Foundation 1460 non-null object 30 BsmtQual 1460 non-null object 31 BsmtCond 1460 non-null object 32 BsmtExposure 1460 non-null object 33 BsmtFinType1 1460 non-null object 34 BsmtFinSF1 1460 non-null int64 35 BsmtFinType2 1460 non-null object 36 BsmtFinSF2 1460 non-null int64 37 BsmtUnfSF 1460 non-null int64 38 TotalBsmtSF 1460 non-null int64 39 Heating 1460 non-null object 40 HeatingQC 1460 non-null object 41 CentralAir 1460 non-null object 42 Electrical 1459 non-null object 43 1stFlrSF 1460 non-null int64 44 2ndFlrSF 1460 non-null int64 45 LowQualFinSF 1460 non-null int64 46 GrLivArea 1460 non-null int64 47 BsmtFullBath 1460 non-null int64 48 BsmtHalfBath 1460 non-null int64 49 FullBath 1460 non-null int64 50 HalfBath 1460 non-null int64 51 BedroomAbvGr 1460 non-null int64 52 KitchenAbvGr 1460 non-null int64 53 KitchenQual 1460 non-null object 54 TotRmsAbvGrd 1460 non-null int64 55 Functional 1460 non-null object 56 Fireplaces 1460 non-null int64 57 FireplaceQu 1460 non-null object 58 GarageType 1460 non-null object 59 GarageYrBlt 1460 non-null float64 60 GarageFinish 1460 non-null object 61 GarageCars 1460 non-null int64 62 GarageArea 1460 non-null int64 63 GarageQual 1460 non-null object 64 GarageCond 1460 non-null object 65 PavedDrive 1460 non-null object 66 WoodDeckSF 1460 non-null int64 67 OpenPorchSF 1460 non-null int64 68 EnclosedPorch 1460 non-null int64 69 3SsnPorch 1460 non-null int64 70 ScreenPorch 1460 non-null int64 71 PoolArea 1460 non-null int64 72 PoolQC 1460 non-null object 73 Fence 1460 non-null object 74 MiscFeature 1460 non-null object 75 MiscVal 1460 non-null int64 76 MoSold 1460 non-null int64 77 YrSold 1460 non-null int64 78 SaleType 1460 non-null object 79 SaleCondition 1460 non-null object 80 SalePrice 1460 non-null int64 dtypes: float64(3), int64(34), object(44) memory usage: 924.0+ KB
unique_values = []
for col in object_cols:
unique_values.append(df[col].unique().size)
plt.figure(figsize=(10,6))
plt.title('No. Unique values of Categorical Features')
plt.xticks(rotation=90)
sns.barplot(x=object_cols,y=unique_values)
<Axes: title={'center': 'No. Unique values of Categorical Features'}>
plt.figure(figsize=(30, 56))
plt.title('Categorical Features: Distribution')
plt.xticks(rotation=90)
index = 1
for col in object_cols:
y = df[col].value_counts()
plt.subplot(11, 4, index)
plt.xticks(rotation=90)
sns.barplot(x=list(y.index), y=y)
index += 1
C:\Users\HP\AppData\Local\Temp\ipykernel_11432\4165315780.py:8: MatplotlibDeprecationWarning: Auto-removal of overlapping axes is deprecated since 3.6 and will be removed two minor releases later; explicitly call ax.remove() as needed. plt.subplot(11, 4, index)
sns.boxenplot(x=df["SalePrice"])
<Axes: xlabel='SalePrice'>
sns.lmplot(x = "SalePrice", y = "GarageArea",
hue = "LotShape", data = df, legend = True,aspect=20/12)
<seaborn.axisgrid.FacetGrid at 0x2d67a1f59f0>
sns.boxenplot(data=df, x="SalePrice", y="MSZoning", scale="linear")
<Axes: xlabel='SalePrice', ylabel='MSZoning'>
g = sns.JointGrid(data=df, x="SalePrice", y="LotArea")
g.plot_joint(sns.scatterplot, s=100, alpha=.5)
g.plot_marginals(sns.histplot, kde=True)
<seaborn.axisgrid.JointGrid at 0x2d679d99c00>
sns.catplot(data=df, x="HouseStyle", y="SalePrice", aspect= 20/18)
<seaborn.axisgrid.FacetGrid at 0x2d673cfd1b0>
sns.catplot(data=df, x="SalePrice", y="Neighborhood", kind="box")
<seaborn.axisgrid.FacetGrid at 0x2d671021f30>
sns.catplot(data=df, x="SalePrice", y="BldgType", kind="box")
<seaborn.axisgrid.FacetGrid at 0x2d673cfd9c0>
#Scatter plot to find relation between GarageArea and SalePrice
sns.set_style('darkgrid')
plt.figure(figsize=(8,6))
sns.scatterplot(data=df, x='GarageArea', y='SalePrice', s=80, alpha=0.7, color="#008080")
plt.title("Sale Price vs. Garage Area", fontsize=18)
plt.xlabel("Garage Area", fontsize=12)
plt.ylabel("Sale Price", fontsize=12)
plt.xticks(fontsize=10)
plt.yticks(fontsize=10)
plt.show()
sns.lineplot(data=df, x="SalePrice", y="GarageArea")
<Axes: xlabel='SalePrice', ylabel='GarageArea'>
sns.distplot((df['SalePrice']))
plt.show()
C:\Users\HP\AppData\Local\Temp\ipykernel_11432\873051638.py:1: UserWarning: `distplot` is a deprecated function and will be removed in seaborn v0.14.0. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms). For a guide to updating your code to use the new functions, please see https://gist.github.com/mwaskom/de44147ed2974457ad6372750bbe5751 sns.distplot((df['SalePrice']))
# Distplot of log transformed SalePrice to reduce skewness.
sns.distplot(np.log(df['SalePrice']))
plt.show()
C:\Users\HP\AppData\Local\Temp\ipykernel_11432\2565266045.py:2: UserWarning: `distplot` is a deprecated function and will be removed in seaborn v0.14.0. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms). For a guide to updating your code to use the new functions, please see https://gist.github.com/mwaskom/de44147ed2974457ad6372750bbe5751 sns.distplot(np.log(df['SalePrice']))
# Transforming 'SalePrice'
df['SalePrice_log_trans']= np.log(df['SalePrice'])
# Dropping ID Column and SalePrice
df.drop(['SalePrice','Id'], axis=1, inplace= True)
df.shape
(1460, 80)
df.shape
(1460, 80)
# Train-Test Split
y= df['SalePrice_log_trans']
X= df.drop('SalePrice_log_trans', axis= 1)
X_train, X_test, y_train, y_test= train_test_split(X, y, train_size= .7, random_state= 42)
df.shape
(1460, 80)
# Getting index values of train test dataset
train_index= X_train.index
test_index= X_test.index
# Performing Statistical Imputation for missing values in LotFrontage, MasVnrArea, MasVnrType, Electrical columns
df['LotFrontage'].fillna(X_train['LotFrontage'].median(), inplace= True)
df['LotFrontage'].fillna(X_train['LotFrontage'].median(), inplace= True)
df['MasVnrArea'].fillna(X_train['MasVnrArea'].median(), inplace= True)
df['MasVnrArea'].fillna(X_train['MasVnrArea'].median(), inplace= True)
df['MasVnrType'].fillna(X_train['MasVnrType'].mode(), inplace= True)
df['MasVnrType'].fillna(X_train['MasVnrType'].mode(), inplace= True)
df['Electrical'].fillna(X_train['Electrical'].mode(), inplace= True)
df['Electrical'].fillna(X_train['Electrical'].mode(), inplace= True)
# Getting object and numeric type columns
housing_cat= df.select_dtypes(include= 'object')
housing_num= df.select_dtypes(exclude= 'object')
housing_cat.describe()
| MSSubClass | MSZoning | Street | Alley | LotShape | LandContour | Utilities | LotConfig | LandSlope | Neighborhood | ... | GarageType | GarageFinish | GarageQual | GarageCond | PavedDrive | PoolQC | Fence | MiscFeature | SaleType | SaleCondition | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| count | 1460 | 1460 | 1460 | 1460 | 1460 | 1460 | 1460 | 1460 | 1460 | 1460 | ... | 1460 | 1460 | 1460 | 1460 | 1460 | 1460 | 1460 | 1460 | 1460 | 1460 |
| unique | 15 | 5 | 2 | 3 | 4 | 4 | 2 | 5 | 3 | 25 | ... | 7 | 4 | 6 | 6 | 3 | 4 | 5 | 5 | 9 | 6 |
| top | 20 | RL | Pave | Not Present | Reg | Lvl | AllPub | Inside | Gtl | NAmes | ... | Attchd | Unf | TA | TA | Y | Not Present | Not Present | Not Present | WD | Normal |
| freq | 536 | 1151 | 1454 | 1369 | 925 | 1311 | 1459 | 1052 | 1382 | 225 | ... | 870 | 605 | 1311 | 1326 | 1340 | 1453 | 1179 | 1406 | 1267 | 1198 |
4 rows × 44 columns
# 'Street','Utilities', 'CentralAir' have 2 unique data, so we are encoding with 0 and 1
df['Street']= df.Street.map(lambda x: 1 if x== 'Pave' else 0)
df['Utilities']= df.Utilities.map(lambda x: 1 if x== 'AllPub' else 0)
df['CentralAir']= df.CentralAir.map(lambda x: 1 if x== 'Y' else 0)
# Performing get_dummies
cat_cols= housing_cat.columns.tolist()
done_encoding= ['Street','Utilities', 'CentralAir']
cat_cols= [col for col in cat_cols if col not in done_encoding]
dummies= pd.get_dummies(df[cat_cols], drop_first=True)
C:\Users\HP\AppData\Local\Temp\ipykernel_11432\59568176.py:5: FutureWarning: In a future version, the Index constructor will not infer numeric dtypes when passed object-dtype sequences (matching Series behavior) dummies= pd.get_dummies(df[cat_cols], drop_first=True)
# Checking all dummies
dummies.head()
| MSSubClass_30 | MSSubClass_40 | MSSubClass_45 | MSSubClass_50 | MSSubClass_60 | MSSubClass_70 | MSSubClass_75 | MSSubClass_80 | MSSubClass_85 | MSSubClass_90 | ... | SaleType_ConLI | SaleType_ConLw | SaleType_New | SaleType_Oth | SaleType_WD | SaleCondition_AdjLand | SaleCondition_Alloca | SaleCondition_Family | SaleCondition_Normal | SaleCondition_Partial | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 |
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 |
| 2 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 |
| 3 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 4 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 |
5 rows × 234 columns
# Concatinating dummies with housing_df dataframe and droping original features
print('housing_df before droping original valiables', df.shape)
print('shape of dummies dataframe', dummies.shape)
df.drop(cat_cols, axis=1, inplace= True)
df= pd.concat([df, dummies], axis= 1)
print('final shape of housing_df', df.shape)
housing_df before droping original valiables (1460, 80) shape of dummies dataframe (1460, 234) final shape of housing_df (1460, 273)
X_train=X_train.drop('Utilities',axis=1)
# Re-constructing Train-test data
X_train= df.iloc[train_index, :].drop('SalePrice_log_trans', axis= 1)
y_train= df.iloc[train_index, :]['SalePrice_log_trans']
X_test= df.iloc[test_index, :].drop('SalePrice_log_trans', axis= 1)
y_test= df.iloc[test_index, :]['SalePrice_log_trans']
# Performing scaling of numeric columns in training and test dataset using RobustScaler
num_cols= housing_num.columns.tolist()
num_cols.remove('SalePrice_log_trans')
scaler= RobustScaler(quantile_range=(2, 98))
scaler.fit(X_train[num_cols])
X_train[num_cols]= scaler.transform(X_train[num_cols])
X_test[num_cols]= scaler.transform(X_test[num_cols])
# Checking scaled features
X_train[num_cols].head()
| LotFrontage | LotArea | OverallQual | OverallCond | YearBuilt | YearRemodAdd | MasVnrArea | BsmtFinSF1 | BsmtFinSF2 | BsmtUnfSF | ... | GarageArea | WoodDeckSF | OpenPorchSF | EnclosedPorch | 3SsnPorch | ScreenPorch | PoolArea | MiscVal | MoSold | YrSold | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1452 | -0.360825 | -0.255342 | -0.2 | 0.0 | 0.318533 | 0.186441 | 0.126743 | 0.109760 | 0.000000 | -0.290195 | ... | 0.045214 | 0.000000 | 0.003912 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | -0.090909 | -0.50 |
| 762 | 0.020619 | -0.041372 | 0.2 | 0.0 | 0.357143 | 0.254237 | 0.000000 | -0.255872 | 0.000000 | 0.149603 | ... | 0.143361 | 0.367391 | 0.070423 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.000000 | 0.50 |
| 932 | 0.144330 | 0.089208 | 0.6 | 0.0 | 0.328185 | 0.203390 | 0.478454 | -0.272651 | 0.000000 | 0.854362 | ... | 0.335245 | 0.000000 | 0.641628 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | -0.272727 | -0.25 |
| 435 | -0.278351 | 0.045983 | 0.2 | 0.2 | 0.231660 | 0.033898 | 0.000000 | -0.003496 | 0.559168 | -0.248137 | ... | 0.072783 | 0.343478 | 0.133020 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | -0.181818 | 0.25 |
| 629 | 0.123711 | -0.024995 | 0.0 | 0.0 | -0.077220 | -0.508475 | 0.410330 | 0.163591 | 0.546164 | -0.117159 | ... | 0.039700 | 0.382609 | -0.105634 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.000000 | 0.00 |
5 rows × 35 columns
var_t= VarianceThreshold(threshold= .003)
variance_thresh= var_t.fit(X_train)
col_ind= var_t.get_support()
# Below columns have very low variance
X_train.loc[:, ~col_ind].columns
Index(['Utilities', 'MSSubClass_40', 'LotConfig_FR3', 'Neighborhood_Blueste',
'Condition1_RRNe', 'Condition2_Feedr', 'Condition2_PosA',
'Condition2_PosN', 'Condition2_RRAe', 'Condition2_RRAn',
'Condition2_RRNn', 'RoofStyle_Shed', 'RoofMatl_Membran',
'RoofMatl_Metal', 'RoofMatl_Roll', 'RoofMatl_WdShake',
'Exterior1st_AsphShn', 'Exterior1st_BrkComm', 'Exterior1st_CBlock',
'Exterior1st_ImStucc', 'Exterior1st_Stone', 'Exterior2nd_AsphShn',
'Exterior2nd_CBlock', 'Exterior2nd_Other', 'Exterior2nd_Stone',
'ExterCond_Po', 'Foundation_Wood', 'BsmtCond_Po', 'Heating_OthW',
'Heating_Wall', 'HeatingQC_Po', 'Electrical_FuseP', 'Electrical_Mix',
'Functional_Sev', 'GarageQual_Po', 'GarageCond_Po', 'PoolQC_Fa',
'PoolQC_Gd', 'MiscFeature_Othr', 'MiscFeature_TenC', 'SaleType_Con',
'SaleType_ConLI', 'SaleType_ConLw', 'SaleType_Oth'],
dtype='object')
# Checking number of apperance of one of the attributes/categorical value in dataset
df_org.Functional.value_counts()
Typ 1360 Min2 34 Min1 31 Mod 15 Maj1 14 Maj2 5 Sev 1 Name: Functional, dtype: int64
# Removing above columns from train and test dataset
X_train= X_train.loc[:, col_ind]
X_test= X_test.loc[:, col_ind]
# Checking shape of final training dataset
X_train.shape
(1021, 228)
# Selecting few values for alpha
range1= [0.0001, 0.001, 0.01, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
range2= list(range(2, 1001))
range1.extend(range2)
params_grid= {'alpha': range1}
# Applying Ridge and performing GridSearchCV to find optimal value of alpha (lambda)
ridge= Ridge(random_state= 42)
gcv_ridge= GridSearchCV(estimator= ridge,
param_grid= params_grid,
cv= 3,
scoring= 'neg_mean_absolute_error',
return_train_score= True,
n_jobs= -1,
verbose= 1)
gcv_ridge.fit(X_train, y_train)
Fitting 3 folds for each of 1013 candidates, totalling 3039 fits
GridSearchCV(cv=3, estimator=Ridge(random_state=42), n_jobs=-1,
param_grid={'alpha': [0.0001, 0.001, 0.01, 0.05, 0.1, 0.2, 0.3,
0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, ...]},
return_train_score=True, scoring='neg_mean_absolute_error',
verbose=1)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. GridSearchCV(cv=3, estimator=Ridge(random_state=42), n_jobs=-1,
param_grid={'alpha': [0.0001, 0.001, 0.01, 0.05, 0.1, 0.2, 0.3,
0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, ...]},
return_train_score=True, scoring='neg_mean_absolute_error',
verbose=1)Ridge(random_state=42)
Ridge(random_state=42)
# Checking best estimator
gcv_ridge.best_estimator_
Ridge(alpha=8, random_state=42)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
Ridge(alpha=8, random_state=42)
# Checking best MAE
gcv_ridge.best_score_
-0.09512679670344619
# Checking best MAE
gcv_ridge.best_score_
-0.09512679670344619
# Fitting model using best_estimator_
ridge_model= gcv_ridge.best_estimator_
ridge_model.fit(X_train, y_train)
Ridge(alpha=8, random_state=42)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
Ridge(alpha=8, random_state=42)
models = ["RidgeCV", "LassoRegression", "KNN_Regressor","CrossValidationKNN_Regressor", "DecisonTreeRegressor", "GradientBoostingRegressor", "RandomForestRegressor", "AdaBoostRegressor", "CatBoostRegressor", "PassiveAggressiveRegressor"]
r2_test = []
MSE_test = []
RMSE_test = []
MAE_test = []
# Evaluating on training dataset
y_train_pred= ridge_model.predict(X_train)
print(y_train_pred)
print( 'r2 score on training dataset:', r2_score(y_train, y_train_pred))
print( 'MSE on training dataset:', mean_squared_error(y_train, y_train_pred))
print( 'RMSE on training dataset:', (mean_squared_error(y_train, y_train_pred)**.5))
print( 'MAE on training dataset:', mean_absolute_error(y_train, y_train_pred))
[11.75456286 12.24804681 12.5815665 ... 11.72663893 12.09020199 12.19111285] r2 score on training dataset: 0.9201164432816552 MSE on training dataset: 0.012394417531144047 RMSE on training dataset: 0.1113302184096665 MAE on training dataset: 0.07563612980664897
for i in y_train_pred:
print(np.exp(i))
127333.23892736257 208573.50785803667 291142.0289771967 233949.87795376248 166863.04583185492 203503.34497099518 122332.0620204194 183589.19251661166 227696.86992127984 131734.37104145886 161132.1820874082 124317.56127086365 180822.8331452242 243053.72921510044 161346.4390295674 86376.2241589058 205304.6279675122 327713.17929702875 299883.17138348985 231650.81925560845 180059.58582897903 138308.70888626226 114619.34214065524 170721.1874521089 197348.48032837224 157637.76072354472 489603.3100489214 190798.28274265424 190301.12400774434 86512.86860083792 240662.66085969048 104917.06339368118 113902.72006827156 117931.70974667094 112843.11234731445 210150.61287187415 247615.870891639 144283.1610560465 131689.60628359742 129285.22496801421 207891.67060923314 141653.5735063906 170748.54900350433 146660.9812955782 122954.33186160288 220437.82620822667 151048.18600044548 158003.81300205755 96100.15872073203 168649.20990224346 375655.9727959405 238051.95435489746 221564.39611087146 194524.48373768476 300656.07833451487 185404.1736217031 170145.41478155015 220851.68937875063 89381.17946384888 75771.10732038943 165990.10374492352 398301.14295547165 95015.12953537205 108954.94650384203 138652.235979504 166813.02707103392 143213.98306624906 198526.86935704068 162438.216358688 226828.73476031004 114303.53529422641 193065.29312496918 72673.2481780872 153351.0254491409 277427.5209316148 117820.66475894969 137339.43996490916 217501.9355057002 110840.58093970575 235655.74148289053 170953.15615889643 150178.7465879881 186999.38054705464 222242.37638257962 88297.22506277653 204280.77031132326 193268.35159216117 152691.69737041663 144165.95426086942 212896.87090785382 139194.36995012403 282302.1312581991 328417.7765376709 235627.8730167127 155581.21548942785 321329.85684471653 141166.74888329385 134034.60699648203 128355.72712678825 195551.7468504804 156142.77729096767 141844.5472848424 151553.3545077278 301357.2399161335 247066.04700627792 291432.7354219564 260066.3438965061 138963.77655388755 196783.1108801388 157544.3488404373 124283.5966834075 403050.8122478503 111100.97209761044 316385.0095980751 97146.31405962796 157027.84796040354 179271.72189098355 62377.127138012 142647.2997369733 193252.39537224502 242744.3978789793 162592.55630375684 250559.43558023946 131291.0831708077 177607.11685006242 317251.45135412173 157439.4809436702 339000.72340112063 160328.47121878518 247601.7086196421 158313.7310075776 160258.02746886268 79824.77503392253 220087.30465730446 95147.00832302736 136705.24566862412 166097.52558836227 235199.71318867462 161652.77924407975 244184.34991667225 246046.4920363751 168530.38204820603 200555.45216101286 392411.7604434961 146673.544134903 179761.51775917286 155109.90768065964 187781.20213387764 165827.28771246911 217587.8883567749 138065.10205858207 105158.85915524012 84134.67455471493 159508.5894999249 124167.3391550522 112752.83357925048 102329.07289949927 197229.09030590855 108677.39920425045 199442.26586424495 299205.5140742983 212784.02410743354 198309.62522174628 121173.49193814534 129194.67079470774 171214.1649558024 124190.5302151984 290007.94861351216 196295.59309345248 153279.95023328057 127957.65159059488 252450.28314336346 124503.45066356118 155783.4672959196 92380.89405592532 223990.7143119768 192911.73227199982 136296.60668032052 193445.7071881119 185091.36956004667 156870.08622563112 119412.73807865685 192917.19698317617 131816.10351425144 224088.96343747483 277769.73173624254 137212.96976862088 161249.64283335375 236291.09901754247 191377.73280635092 129737.45889947754 136575.63395478917 288178.7695713944 173835.31424159498 223254.73614463847 203217.77341228962 180153.57296724248 202243.80691192846 184204.88226045517 204249.89728672014 202901.3884399804 249995.24706154526 378099.82211114827 212826.92151695618 243400.88322354676 99115.91171849758 428330.4909361963 169087.6151596656 95810.71605646987 160752.72407410265 175027.040236309 111270.31725007521 350046.49379021727 197973.1740493789 165684.92810295883 185722.66231482118 280213.46046808857 190619.64760704094 464518.63501159224 99164.63753970523 133737.62030675056 140675.87671960273 164842.6845289202 55946.38821840021 159956.30167789344 170722.85947496383 131209.93173462703 209812.6267940058 175049.57754417995 127008.72600220358 161395.14747039863 145314.41415618602 157012.54699515263 200899.92091863233 126431.51137270898 221594.78476086643 311061.68826427066 240743.69635932904 177210.9817660315 179643.90056880162 136604.38252660606 370258.83135462855 134539.06404773865 151202.89225278725 166544.5776700128 115220.17244879034 243634.8328173374 106165.93754394603 221356.09599476933 130578.01615777295 181479.37250153293 237890.94799234645 257608.7890440229 167703.24423448692 173607.8629347183 292598.98589388904 189431.46537007284 156719.47478956694 256536.56786210113 253799.66735926602 297143.21345105494 347926.2830335611 111366.15589408325 190645.22171773686 96909.64452071534 189827.08100270518 213648.02183876056 209507.149716428 119588.73405832717 296779.3756383833 126261.71438993703 131258.99544016828 118219.65493213359 80337.52600193527 94073.72800476242 324327.76472588873 130702.77784202203 262842.66922750656 219342.72391759683 129731.07436020143 177760.49283609004 191396.9076226018 95470.30803216605 94886.4125880223 192685.5962545868 258680.06240657353 140999.5914332024 88135.35436788447 256864.40445217353 296106.8086297257 272374.356680676 167359.58894048815 123303.84406363103 189372.4399450568 229620.2563967344 173217.4518541458 189947.19322472383 115234.60899540744 146403.54097737488 161233.21239271358 146733.22640471382 120175.99226769523 155992.98059803832 157458.45500806285 119806.60175208379 170041.83931770644 265270.9747107887 246403.31464142108 205201.8086381698 88214.40806046009 94941.51230572847 223543.70176925266 183150.8878503884 116553.33802469946 338914.7877671788 169840.6802949525 155983.7342988236 170468.22186086228 166569.2437869317 225228.9578309499 215455.55541662232 164026.93576676128 149816.4857449352 108365.123608754 171205.80277015682 172148.87311971257 281758.6282737162 218860.02133585306 199195.8576383195 230712.042354304 260929.17095953782 108513.09767919155 124797.73318685137 112079.48922284952 121656.18927966914 312240.1442656054 122861.37770831677 77410.95655982057 132805.3448142238 122806.85923127246 114850.14367090308 202743.1567993696 217126.09689713575 139978.18989004032 387293.99697008455 137804.14689869876 186356.868199099 112992.5289826745 467146.02055333345 133245.56333275462 236720.03710583353 133729.3918090132 268921.79607556615 134220.8568031534 204693.80911042288 131757.37089084258 189000.7459251834 126347.01254039623 216295.24471097547 229674.74649420963 175412.82925838375 118082.31701978184 129178.73525283203 196119.99301146777 102599.46175874135 220103.449608534 193365.2869950086 116364.01114272831 205374.27247212295 188961.69449705337 206720.1743992551 133430.64300486143 142228.9964676947 157800.33368826535 116370.53914498712 88392.23402410917 189112.90961023077 136460.97271190988 254266.3291717111 227313.43749890587 84962.47820916511 124134.57777693096 192881.5789495889 174761.4646521611 135526.11958120912 210482.92874596128 223444.79832697133 162985.35993243303 169495.3896662614 146413.13251618875 437805.8806474594 132176.1707794561 524721.2541189467 277379.1235714522 79720.3824401706 109004.44346631248 195928.85629899002 105669.93674413692 245635.57288589064 120967.33240008184 146386.88128674225 126372.66080303612 182116.7359181676 232150.88958876274 112872.71680416982 178430.47423034 105902.63474415688 205291.60680178588 217972.99179965912 133266.75167184288 137130.52749171932 284335.2037351825 189618.66425739517 188404.3892873555 137113.92340462888 138229.5363610561 118717.15499554048 167819.939573369 85518.95427231248 206715.89253059123 169698.53941030183 209260.88819575415 157882.94405270615 141087.75717474538 147974.1287833321 189497.1230940885 104838.29965334428 159119.60234341264 144979.52447741164 180840.0849604351 210526.7072758717 104139.39461161837 97110.32506542935 252270.04804605944 182141.59740143947 158921.45448837904 121230.46756826536 110432.59472031164 96137.88219182332 176980.88488326632 325021.9936075194 148431.91644645404 127903.37739169883 260749.85970688742 244886.08312202 226356.44648252486 446321.2325086422 216494.98554468236 153970.97302095493 99223.19915530781 284318.2205007657 250895.53163531655 148060.33758261346 119105.52442630398 62057.38760685618 246283.58819558684 186615.208777736 64874.05840300703 354965.3890709491 213077.77582178355 204935.51144813825 152523.48188402812 182278.43400500074 176057.01425078802 130274.88637552533 258534.58348742442 83086.40167458849 60768.81959549944 218677.32762416493 324253.5977949615 190527.32511773508 156607.83304956259 200518.39909229687 284663.8051367102 147323.93755639845 97023.53365616612 147472.4812541958 136574.0296951808 90762.55702463197 124942.036068403 85501.60194077881 165641.5698079206 166828.86948544782 222167.3939239562 227215.05919997673 142095.47444325706 233041.16170158278 152217.92542062775 111601.15741422998 172160.76842595116 344650.1049653601 403444.8499050614 150318.1922982052 309149.4782053377 108113.08078899128 126981.69486764069 251191.43093011327 263479.45035666693 131894.56621273715 266265.9554461134 152081.65274697656 247869.36046772433 124895.39823093425 164936.8724569761 162337.5227460184 64717.94574094863 81406.5612475226 111909.83972651232 129787.77048823335 174664.16464963133 122322.24221897141 141210.0572844169 209438.46109374936 90042.48225942747 116551.35097459656 155571.79771747708 228730.15080326475 151112.79661368192 78016.83676913667 103252.1408261298 175151.86219868 101207.72504204379 223803.54959934016 127515.01217035906 149806.26113234268 228065.96511247428 151065.71965738456 182847.77679018714 112903.17433823016 78233.31980605958 171886.99511942442 146748.36266571615 338424.28266169806 103684.03867716319 148016.26032709182 312236.12904221297 134528.19372638213 129341.27401483803 91113.9735572344 114672.53916611361 383992.38091716525 210177.4912038266 125326.93320314004 129079.9515836756 98527.17725129248 154591.68775772152 153590.61242209966 147016.92610280652 130057.72401444636 129549.4773282458 293012.20068828936 195773.37936697967 130416.54767006262 220777.22830385462 287963.3422231293 147952.905524253 189102.58198698462 190344.2753748766 106609.50091806304 138180.97012311977 82277.62945490232 145545.7484738237 124748.00281903273 114486.57296218848 150354.028506765 137770.48606862646 59075.21892811964 271305.26380827185 103401.57200952641 199061.97311609736 197244.7352051808 108930.14621461587 338234.26287457184 145962.42343790564 144556.99088771926 198411.9795056991 250345.00496742828 210543.93172146243 126699.12715114385 135732.35278355883 139867.83160284284 222639.9782278527 103934.82638783431 120656.32225463241 234355.76277576707 121216.1685567179 276234.89146495826 273646.4827926582 139498.53159405905 379313.7910158318 130718.95322977689 180342.79346236368 157918.39393225336 138586.33001504626 124117.73844095685 203885.27467407237 202519.80544545013 293475.96784680535 168976.1003136224 125764.2369300127 228941.39356183758 258739.33764955495 171210.6937896812 87729.29415040385 392116.29805929284 212727.1421856236 229008.3910751923 118823.4256558262 105572.66444016408 186432.3327021581 143397.72149268145 219343.44760978743 173808.1539621332 259716.54212351135 211614.21018205068 95476.21001335945 340288.1513563874 92016.659676405 150767.3846121228 165406.54800062667 96373.50318397889 171134.94446221157 160584.61984775646 246259.61978382125 92584.10698099682 130895.31016074761 216262.9682624001 140016.3114763747 145225.15193357426 204373.70335430256 178358.71382005283 132737.79315131702 139578.65398892807 177830.21166027468 198611.6769774408 113088.06897445508 118478.53779282654 139592.67134795102 320445.20398851973 177994.72637853457 127439.53134930175 121861.33191396177 171350.4239316575 186950.51428594737 151435.13991829028 175108.04080489767 179938.4565064066 105916.85000488652 97405.51885745452 104764.35809391705 201407.48892192094 253217.08851352867 255824.05383157363 156455.78966712047 176890.32644516998 138939.92626980183 113494.50691142584 306291.9253987197 128697.1517736812 357065.20454881934 136905.7368117981 186975.90178539534 107545.46406488105 197415.81608232355 246069.8850764352 132606.32860798144 104104.5862555362 131224.17518572562 267565.7035753674 192652.76937728087 323934.19752643583 112391.30621228009 127951.26599388722 171197.2985401388 126576.3643651716 256432.15542012808 149913.7491064891 329196.8293941662 209719.06185085332 170100.16940216284 133134.1817930467 205023.74163448575 200917.93131371983 336405.9031165094 126924.89073890341 213456.20189608802 316109.76407667197 187609.91727836904 213089.1013352327 163812.22434987212 162842.14106234672 185468.44977697267 119378.29072182837 167596.17169685062 115547.94555831738 203029.22827406492 210753.5988661401 127531.96814639989 99630.75509014643 98732.47569642369 238260.14870524613 172824.37204905902 151292.61288174425 205398.6676414141 148310.64318651683 155968.39101047037 102720.95530269618 86723.29313792002 175761.0568533657 188973.45660835804 133441.16482939856 285577.2241591899 113068.60370307196 197977.50665611253 144115.1941220344 71483.6762138788 154851.93845513853 170629.5231031489 246565.56550620875 408006.37616826507 193289.57027852352 144954.1402451612 153572.64381713895 255406.80417172267 127516.97944674216 219301.7672824815 270479.1885862903 160012.2549727123 112060.53514999518 186481.0738963817 117822.5614166602 152026.61500939087 206002.67896345162 120273.77745727723 168513.70941832179 443354.5962043869 228972.77206747193 101218.2962256708 100071.39555299781 139044.38283223132 121820.78797342801 218377.65214428448 200844.44269865865 147468.9792127213 84428.13952107598 143827.1659595985 180565.04651017577 202374.9130645455 165263.7378564397 154985.39064478298 172393.72011398818 247632.21935812713 118899.97175133691 219452.89035569067 239787.55961488964 236960.5415898068 223009.7442168931 176115.5827859285 132103.02493465447 91055.08956692509 91579.02191288304 210738.6680891529 364001.40367379255 151198.52480488137 179645.679269342 215304.54771378732 135864.32273276694 97920.0062945486 193114.50405882555 182786.41237657884 122157.2967806471 69377.15896295548 94632.53186228566 297475.24758813245 314937.31686997943 245731.91191651873 125366.48969229634 131324.39250405907 222665.84656582066 101295.0170066642 132841.03809726564 111677.01715176234 140205.40629510843 220654.25093282008 211700.9154235758 171106.38962124012 87657.72064663903 94596.09859354405 152327.87808241355 126353.66040064936 166556.3855460658 136476.40165660373 271883.6628558678 158731.85581086375 135468.3195116327 137369.8016804096 264142.25893427065 139630.0344740951 243084.69749925067 142244.0208264484 238155.3496842972 126927.49113306444 81788.8665481538 172119.62556032476 114189.37060644176 110051.23217212208 125097.283073282 108127.29766429603 157432.0860527658 171552.20951208338 185586.85082796167 180633.9919311732 208290.80460412198 352764.7251064748 219396.74789612996 162318.38620896076 320839.2734265796 212939.6818262936 126720.8898678204 215684.39173632878 211410.2408460766 183850.03032122055 256418.14832361127 134137.62635348967 211896.2600671202 119171.0663173729 132034.23477962503 134317.3879070568 257880.56080133579 244746.19119817016 117648.53806079608 241748.3233245022 253142.30082951623 165441.6652304304 179968.511947848 236654.75151925778 196055.61514509216 349832.517515057 136767.32979285961 160398.39951461548 122751.42906638271 137090.19554811323 275863.2846874831 99247.67961753777 116695.16700361457 293415.71231366176 128577.2787483252 189371.4531241025 88876.13097274888 151540.05578000937 258604.190470191 145864.40329839312 117808.02963986737 158017.79384584646 125018.83532154332 155375.8730563356 163898.9926327793 142665.17626546227 196769.2220238655 184676.13242710778 214605.54196140476 170718.92394539568 143654.1063308217 173832.20878961924 139960.22797397707 121754.78202735564 151583.94520099694 301404.1679650813 112474.50218513368 126630.60585848268 287493.16232288576 193565.76090294693 313104.7326393013 148364.19789887665 254554.81761378172 168178.53389632003 130395.42946206963 185335.31520186606 152600.46742820012 160797.5839369742 160830.88711930008 174325.43988353192 138158.27082962656 169465.87725981144 91134.33008401401 132653.56995203788 105873.98043434956 200336.97343380903 95039.26511621474 137196.64628916496 185813.16220580792 153995.74929254706 238834.23321896885 115196.64760826579 338465.6538434029 252564.63256164832 118746.23697765308 114477.16935899772 278595.13521606417 82778.52500030688 99702.70126841015 113507.05273318476 131050.85917444719 150757.14596646547 222949.01862775092 207973.44517623767 148864.5715688984 128689.82392821084 174167.6589839884 198877.55736987398 148856.82356079482 196666.5025227227 135697.45934838592 338834.7522067507 112753.1011563246 108484.15301517973 228269.67418935415 145455.24052115675 129066.68967841541 93522.6969384724 155682.17943342178 217792.32358293742 89061.62460406826 224444.21183297556 145169.94451135126 212902.37554200497 156203.97385914906 171803.2069392909 176092.987375389 139853.65771972 303806.21819781815 205836.8670684246 161934.93731652314 171308.2356044546 133171.63856739804 215300.72866625464 142956.02883304976 152421.16767157658 233126.99532689722 127153.22051376446 167050.9671365788 245069.98449979964 195673.9874401766 157641.46242584524 123966.72739496906 159631.86472539807 388720.7203065679 100801.94500779663 209695.49690865673 347351.4412297107 130280.2749531233 128256.00427898984 208255.0442582803 128489.49639753731 108566.706891431 188140.4218384584 272344.65447417006 153270.6027204605 174340.103966491 149527.85884163203 209960.02876500387 112242.8855114362 170949.8870213307 143645.82866784168 285112.1134283608 245764.48091558408 230576.42921863476 95689.29163879309 226455.979585321 202238.04754516517 286695.809520432 133623.83081405403 141253.9765557805 192708.70492903393 139392.25405029533 334513.2855562916 107556.92385587745 224328.63066439822 159656.61966458117 327635.9900112592 104028.53233745246 139108.17902289357 211894.7171029414 129479.62035558932 273396.39984599967 170920.91004539037 206133.93440532358 151190.39658290517 195822.27583614175 244449.0820941035 148484.36574059108 221090.49813155615 178454.44677118503 127050.46987302776 56948.757100658055 127549.86063553474 205582.07225218997 192228.15115199488 155562.4421696797 117048.78653426451 201142.5742513097 207178.21298729954 350110.74876286654 282664.874307423 525382.0812306624 110273.07465652331 206910.7884104419 180265.54382261907 103159.52472691388 153709.25499017796 166311.94711511422 146247.90734437137 141668.94397711245 168359.133977107 97516.07988487264 290463.84699975664 186050.5119484194 142436.3266854606 123826.77947446151 178118.08150642234 197030.30893066962
# Evaluating on testing dataset
y_test_pred= ridge_model.predict(X_test)
print( 'r2 score on testing dataset:', r2_score(y_test, y_test_pred))
print( 'MSE on testing dataset:', mean_squared_error(y_test, y_test_pred))
print( 'RMSE on testing dataset:', (mean_squared_error(y_test, y_test_pred)**.5))
print( 'MAE on testing dataset:', mean_absolute_error(y_test, y_test_pred))
r2_test.append(r2_score(y_test, y_test_pred))
MAE_test.append(mean_absolute_error(y_test, y_test_pred))
MSE_test.append(mean_squared_error(y_test, y_test_pred))
RMSE_test.append(mean_squared_error(y_test, y_test_pred)**.5)
r2 score on testing dataset: 0.8913491323321061 MSE on testing dataset: 0.018390937818633723 RMSE on testing dataset: 0.13561319190489443 MAE on testing dataset: 0.09439608138185188
for i in y_test_pred:
print(np.exp(i))
150735.2173466355 327083.6638099437 96828.74185150988 162213.49177661867 333003.0906641252 82119.17115822945 246776.8793595377 143813.03171055517 80459.13839639693 140966.8197294994 139909.6769476796 120237.35939387666 98521.76639556917 218672.8270382295 174030.23173920123 134009.15258230607 193466.61148764595 127894.71654342613 103516.09896505387 212001.78806138437 169321.41681099503 200757.1925063746 185820.5063071731 136825.27477528737 202915.0689299567 156158.9275426897 198881.01262352554 108490.13753158116 175423.3374904713 206394.63228826024 129340.11496624025 275593.3519763146 196043.54456802664 112148.08588833177 273206.40275152907 148552.15697685102 142181.0277276108 205171.31940382672 329648.6711368386 105422.3014634065 140097.5735545357 229478.4813055007 113332.4093851592 331367.5416364594 131502.51098866382 134612.2433938876 112726.95181570157 131246.85942803763 430274.5893622336 123821.93711216956 119505.40611666601 209962.93247040347 107712.43084695209 270216.6887177057 168483.57812665185 217754.95932222583 218209.58715644127 165029.19414189967 131846.05570798888 106627.82895726095 73698.51926582218 172978.65761425463 307429.3001049602 243578.7029332213 317854.2242451331 192822.8138043959 105068.81912743968 321353.4006618814 112605.9695346746 167755.61207695858 122764.96412114693 128758.31137518657 116215.89293211972 86087.2489417939 428813.05817903206 193933.15046739177 286967.19607424986 330921.3946769626 151133.21300143993 115759.0088801804 115763.09987759333 70076.97897475059 112329.93807792499 100750.50014535431 159206.24377671126 129938.66521637306 254753.15410393968 213808.07599571938 148143.47958357743 201284.21212184694 122751.86637328789 144626.10507313142 140224.09876903603 270874.52557466703 103787.84517303946 192695.5059243658 178791.57103997006 183452.6932060958 193038.83072526733 275387.5451828769 143781.44093714503 210348.91576874035 231749.270609864 137202.52141454775 184136.29440174377 186492.14810703366 160960.3923040032 271971.25705299474 147989.41078091497 208174.1516403631 53817.272334463414 116448.22579351619 146507.58479341987 142454.70812192463 198678.296021018 113719.0078151672 109109.74541743049 117194.3023909564 115724.90840327597 269856.606787931 127856.71113586493 146820.97196094596 179402.88323772795 190037.31479794427 188703.71606931722 133635.39218410745 231163.54489051373 94922.85470912547 151452.28342292266 199132.96306083264 190769.32166558225 324972.9378374554 186683.25206678157 121500.779012891 73791.99410811244 370383.1573755339 323411.19378962915 139358.35229984092 216310.63824827355 587942.2756609976 336719.0929464394 134319.33640599015 174717.5940497322 154992.2617099829 120294.94440988354 125749.59214120005 245972.057988954 186289.13889458927 126830.53662916987 68125.84797854928 120504.06935816791 134535.59761844203 244773.52633199107 148084.72149490102 74641.70166590126 120428.95621701163 116664.61190901743 134976.34291549562 91729.5139385925 136245.5386042893 202433.12452094426 115531.11317185454 292108.83274898486 144074.4099222766 114624.36389108787 119378.69278935707 253319.65674007646 306031.7540850738 459176.4122431546 222185.31884008416 379130.0284194708 88158.75472929257 112931.69362491797 155716.14790742233 304645.1134859151 116984.11403564444 119229.40554962863 217421.49780789603 125943.54741839814 159301.42122674827 192088.3299847548 99612.00983700246 126021.6351191492 142856.28633333102 246545.51959904356 115889.826084962 275585.44684241194 223062.2048039057 202304.64258045782 86911.57450822573 113846.53142805534 101130.92522053103 147508.26566810143 132211.36918780327 198555.3650401231 168201.3476827777 211873.18666337218 96942.49630405079 207864.18430877084 142821.74649795605 234993.24406061348 212517.97097463114 113959.1762003826 294836.06916358176 199935.45923070674 126661.50392500096 229001.79980670544 130225.22243716735 131492.8965521864 115170.50522967547 223706.45456332408 160206.34808415535 110154.801911343 162899.74758158685 220203.64753636738 241470.56183697446 210572.51584651545 133733.43211846423 124941.5222725225 132964.96238147657 135671.42175381293 227776.14669684472 193953.3111584902 100253.27666038697 231971.23961545934 136043.6713398109 97523.32764253029 105337.84205491914 160346.92386827464 107288.90463196131 101457.08810600481 174878.7812575781 122288.28312562015 117806.28540853807 227948.1509806138 147555.8926637416 201317.4857197945 156008.0508989371 234257.99701001612 129663.33331152564 105593.94120617902 250486.59408730073 218593.02719391102 468969.0003913071 197112.273389027 116879.06308613627 149268.76532888075 176364.29317683898 140290.3625389415 99879.75366916142 168551.22951677488 180560.39104543807 147215.2487514563 97164.41266546008 146189.63269233008 144906.8208619076 114441.95768811267 117875.70660239753 176058.17571147988 243317.80197172915 286727.62354087044 192710.92036343232 132797.26237854478 227281.42211742635 332348.79916841444 227818.14894061518 150819.7265604407 140349.16800388205 120538.46667853782 191661.86036278235 392726.82859860716 232301.8302559192 234822.50020278618 92309.35973311077 95653.07868523819 134900.15299986754 130082.57991457354 272321.2105241992 219303.9567029591 132687.8411178693 202480.5680651995 91645.5696778579 195105.3182812641 109554.55117372019 297052.0532487567 173792.63170505513 205261.11892576326 109370.19378191044 262084.7816807495 206585.72169482737 117818.6648618387 122910.64874061522 131998.3640963936 179594.37758856342 87661.7784974647 162276.08026935346 167858.1211098538 137522.10067338144 180277.15029511356 113909.88090744325 186187.56980169375 224806.47088545258 131271.5646192059 130466.8094944758 171837.89846524404 191480.60162570266 148098.95870182736 211733.8204216473 212399.5504587129 114844.35470790976 131333.26770818143 175362.23615365478 97074.31775092235 200886.06320338298 124744.13310439304 179822.3896325833 186717.4994681763 171725.41205348162 297099.0366806703 79810.73269177122 216335.66179885523 139719.48198529784 136728.36389612043 81160.13188784542 196380.91923064587 145974.9704653123 138184.56997726654 225082.27363405036 149750.2083013327 103791.09672887235 144745.72666205076 136471.63961238053 150829.31979133794 195139.2773015012 153211.3953989849 126496.51959231241 167430.7506966108 87801.01010980232 73475.13971658582 202150.5219939303 194180.3256744107 144039.61031668872 126276.54977967519 186423.005787735 231961.888797617 356324.42468440486 355578.69036073005 106297.79777748857 227452.05328500335 124664.4942216886 234460.4579804484 324170.6068103444 272085.6393480761 173547.81830268915 224848.12497194076 127701.87948101177 121237.99721900608 86412.46133776703 213111.59349389016 327895.3326493224 186025.5506239508 127170.6144340355 224793.45960263783 234035.39091388002 133200.09871961412 190724.10654111355 157424.23382510935 108758.39684437477 124710.12414100043 152818.35015453215 121520.50643196478 178402.82666134587 116438.41297767674 204133.8357710124 182086.58149003366 130912.47800258629 222882.00272039342 190525.55047814787 95845.69083560685 203478.52614728268 142473.1259137855 176234.7410473875 193489.60402699368 156529.77964211916 126309.29799173087 232998.36790822257 138631.11971559774 122474.14882826185 265135.292584789 171526.01509876113 122460.67438792865 132315.0132723657 142346.41582536913 351155.9579862824 137965.90198626736 419282.04756298877 127587.32771252359 196620.68857431458 175209.22681100023 131212.35227614423 167810.59557378423 373032.9477611025 101298.79389224389 157792.31010982458 143877.74818413498 99438.15953428613 182056.29643395919 130268.21661024766 211274.568786759 214805.52056333103 245990.80985750098 216362.0177583791 100261.21978645919 323927.4783208876 153877.35357168005 343255.8822603205 132615.24259994813 354942.9677982906 264661.2095157655 125454.68797940049 211195.42606899797 270167.29726576287 217193.14648219672 182266.94623226544 284014.1183189743 116410.8584928174 226141.7552369045 185789.48807247533 215685.97398544697 226791.17471556904 118566.80471732437 149648.00927417117 158091.21568782863 132876.084697309 126090.14264508094 204190.98836965678 131243.08235651837 414117.213085483 177627.6197748688
# Ridge coefficients
ridge_model.coef_
array([-2.68486138e-02, 3.25984187e-02, 7.67999217e-03, 2.19070944e-01,
1.27389413e-01, 7.68847213e-02, 6.90005647e-02, 1.45548621e-05,
-1.00769981e-02, 2.41648538e-02, 1.26788683e-02, 1.08076557e-02,
6.99045317e-02, 9.05899110e-02, 1.06628751e-01, 1.82432938e-04,
1.38964623e-01, 4.31122559e-02, 3.90062159e-03, 8.52713813e-02,
4.45029301e-02, 5.05283578e-02, -4.62548322e-02, 9.83769993e-02,
3.62528011e-02, 1.57014922e-02, 1.21569048e-01, 5.46275531e-02,
4.93926839e-02, -7.11339009e-03, 2.88382885e-02, 2.69050509e-04,
5.48497953e-02, -1.20117916e-04, -3.47185146e-03, 1.62497468e-02,
-1.00239050e-02, -8.82321522e-02, -6.69858563e-03, 8.03367994e-03,
-1.10268258e-02, 4.30327482e-02, 2.62107447e-02, -6.20766071e-03,
4.52784252e-03, -6.64061581e-03, -2.60787175e-02, -7.84081439e-02,
-2.02387769e-02, -1.01941404e-02, 4.35262269e-02, 1.33273910e-02,
3.89371192e-02, -9.51557034e-03, -2.41207552e-02, 4.40509615e-02,
2.49490273e-02, -5.44378010e-02, -2.44175106e-03, 8.15345797e-02,
3.28624045e-02, 5.96515707e-02, 3.25897930e-02, -3.81416500e-02,
-1.46270453e-02, 1.57822895e-03, 1.17632622e-02, -5.30470682e-03,
2.64215501e-02, 3.91088889e-02, -1.89016845e-02, 8.26779255e-02,
-6.92562205e-02, -3.12183577e-02, -4.30975525e-02, -7.93451573e-02,
-2.32400897e-02, -3.41804667e-02, 1.38885111e-02, -1.85211778e-02,
6.88909570e-02, 7.93038850e-02, -3.96363282e-02, -2.78036957e-02,
-2.41758275e-02, -9.70326211e-03, 3.64902074e-02, 1.13146011e-01,
5.16089031e-03, 3.22502121e-02, 2.20332911e-03, 5.47113701e-02,
6.85172128e-03, -7.44529994e-03, -3.58050471e-02, 2.42455280e-02,
1.07718113e-02, 6.67939311e-02, -8.26948217e-03, -6.64061581e-03,
-6.73367586e-02, -5.73888798e-02, 1.74873846e-02, 3.91017522e-02,
-1.72989314e-02, 1.22285381e-02, -2.72121605e-02, -2.19779472e-02,
-8.41581125e-03, -4.10320521e-02, -1.18748574e-02, -2.68861013e-02,
2.54209522e-02, 2.71363173e-02, 2.29451919e-02, 4.83864592e-02,
9.16364124e-02, 1.73203289e-03, -2.05187832e-02, 1.46734906e-02,
1.25317200e-02, -1.78487288e-02, -5.19926718e-03, -3.65685002e-02,
-1.84778549e-02, -3.56449953e-02, -5.14538908e-03, 1.16782629e-02,
4.18363253e-03, 3.85791625e-02, -1.29277877e-02, -2.08613278e-02,
-1.86895291e-02, -4.40237076e-03, 3.39652024e-02, -1.88012398e-02,
1.13271360e-02, 8.36534927e-03, 2.45415730e-02, -8.28852360e-03,
4.82706456e-03, -1.76668608e-02, -1.60984602e-02, -3.49809990e-03,
1.42257081e-02, 1.66119098e-02, 4.52983537e-02, -1.15018027e-02,
9.92988114e-03, -4.15802973e-02, -5.85544258e-02, -2.55791409e-02,
-7.95134627e-02, 4.33544405e-02, -2.55791409e-02, 5.87214763e-02,
5.45956833e-02, -1.01162985e-02, -2.07248832e-02, -2.55791409e-02,
-6.21031836e-03, 1.93632295e-02, -1.87685253e-02, -2.55791409e-02,
1.44113218e-03, -4.99308803e-02, -2.00349920e-02, 7.83523666e-03,
1.00696330e-03, -2.55791409e-02, -5.58322032e-03, 9.61800546e-03,
2.29154827e-02, 4.59712787e-02, -5.01517788e-02, -3.38545126e-02,
-2.68944733e-02, -2.24606606e-02, -4.47035091e-03, 1.00402531e-03,
-1.74651192e-02, -5.45682494e-02, -6.86612916e-02, -6.83706740e-02,
1.19231754e-02, 5.68437034e-03, -7.61199713e-03, 5.47493453e-02,
-2.36024908e-02, -7.73025457e-03, -4.50070068e-02, -2.04708996e-02,
5.16088738e-03, 2.88619344e-02, 9.18994326e-03, 1.40302450e-02,
-2.02747668e-02, 1.49064814e-02, -1.66274987e-02, -1.66274987e-02,
7.40472825e-03, -7.94470159e-03, -2.16196064e-02, 1.61777832e-02,
-1.66274987e-02, -1.96639788e-02, -3.17485529e-02, -9.69551029e-05,
-1.66274987e-02, -8.41765529e-03, 1.38405398e-02, 2.21614254e-02,
3.11884961e-02, -3.58279760e-02, -4.48912605e-03, -1.28962890e-02,
-2.45060636e-03, 1.63913716e-02, 3.62826396e-03, 2.63281115e-02,
5.12683485e-02, 2.01528220e-02, -1.78403699e-02, 1.76623635e-02,
6.80454356e-02, -7.34906196e-03, 3.81073855e-02, 2.87768795e-02])
# Ridge intercept
ridge_model.intercept_
11.666728523280653
# Top 10 features with double the value of optimal alpha in Ridge
ridge_coef= pd.Series(ridge_model.coef_, index= X_train.columns)
top_25_ridge= ridge_coef[abs(ridge_coef).nlargest(25).index]
top_25_ridge
OverallQual 0.219071 GrLivArea 0.138965 OverallCond 0.127389 GarageCars 0.121569 Neighborhood_StoneBr 0.113146 2ndFlrSF 0.106629 TotRmsAbvGrd 0.098377 Exterior1st_BrkFace 0.091636 1stFlrSF 0.090590 MSSubClass_30 -0.088232 FullBath 0.085271 Neighborhood_Crawfor 0.082678 LandContour_HLS 0.081535 BsmtQual_TA -0.079513 Neighborhood_MeadowV -0.079345 Neighborhood_NridgHt 0.079304 MSSubClass_160 -0.078408 YearBuilt 0.076885 CentralAir 0.069905 Neighborhood_Edwards -0.069256 YearRemodAdd 0.069001 Neighborhood_NoRidge 0.068891 KitchenQual_TA -0.068661 Functional_Maj2 -0.068371 SaleCondition_Alloca 0.068045 dtype: float64
Lasso Regression
# Applying Lasso and performing GridSearchCV to find optimal value of alpha (lambda)
params_grid= {'alpha': range1}
lasso= Lasso(random_state= 42)
lasso_gcv= GridSearchCV(estimator= lasso,
param_grid= params_grid,
cv= 3,
scoring= 'neg_mean_absolute_error',
return_train_score= True,
n_jobs= -1,
verbose= 1)
lasso_gcv.fit(X_train, y_train)
Fitting 3 folds for each of 1013 candidates, totalling 3039 fits
GridSearchCV(cv=3, estimator=Lasso(random_state=42), n_jobs=-1,
param_grid={'alpha': [0.0001, 0.001, 0.01, 0.05, 0.1, 0.2, 0.3,
0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, ...]},
return_train_score=True, scoring='neg_mean_absolute_error',
verbose=1)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. GridSearchCV(cv=3, estimator=Lasso(random_state=42), n_jobs=-1,
param_grid={'alpha': [0.0001, 0.001, 0.01, 0.05, 0.1, 0.2, 0.3,
0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, ...]},
return_train_score=True, scoring='neg_mean_absolute_error',
verbose=1)Lasso(random_state=42)
Lasso(random_state=42)
# Checking best estimator
lasso_gcv.best_estimator_
Lasso(alpha=0.001, random_state=42)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
Lasso(alpha=0.001, random_state=42)
# Checking best MAE
lasso_gcv.best_score_
-0.09436232253377737
range3= [0.00005, 0.00006, 0.00007, 0.00008, 0.00009, 0.0001, .0002, .0003, .0004, .0005, .0006, .0007, .0008, .0009, .001]
params_grid= {'alpha': range3}
lasso_gcv= GridSearchCV(estimator= lasso,
param_grid= params_grid,
cv= 3,
scoring= 'neg_mean_absolute_error',
return_train_score= True,
n_jobs= -1,
verbose= 1)
lasso_gcv.fit(X_train, y_train)
Fitting 3 folds for each of 15 candidates, totalling 45 fits
GridSearchCV(cv=3, estimator=Lasso(random_state=42), n_jobs=-1,
param_grid={'alpha': [5e-05, 6e-05, 7e-05, 8e-05, 9e-05, 0.0001,
0.0002, 0.0003, 0.0004, 0.0005, 0.0006,
0.0007, 0.0008, 0.0009, 0.001]},
return_train_score=True, scoring='neg_mean_absolute_error',
verbose=1)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. GridSearchCV(cv=3, estimator=Lasso(random_state=42), n_jobs=-1,
param_grid={'alpha': [5e-05, 6e-05, 7e-05, 8e-05, 9e-05, 0.0001,
0.0002, 0.0003, 0.0004, 0.0005, 0.0006,
0.0007, 0.0008, 0.0009, 0.001]},
return_train_score=True, scoring='neg_mean_absolute_error',
verbose=1)Lasso(random_state=42)
Lasso(random_state=42)
# Checking best estimator
lasso_gcv.best_estimator_
Lasso(alpha=0.0006, random_state=42)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
Lasso(alpha=0.0006, random_state=42)
# Fitting model using best_estimator_
lasso_model= lasso_gcv.best_estimator_
lasso_model.fit(X_train, y_train)
Lasso(alpha=0.0006, random_state=42)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
Lasso(alpha=0.0006, random_state=42)
# Evaluating on training dataset
y_train_pred= lasso_model.predict(X_train)
print( 'r2 score on training dataset:', r2_score(y_train, y_train_pred))
print( 'MSE on training dataset:', mean_squared_error(y_train, y_train_pred))
print( 'RMSE on training dataset:', (mean_squared_error(y_train, y_train_pred)**.5))
print( 'MAE on training dataset:', mean_absolute_error(y_train, y_train_pred))
r2 score on training dataset: 0.9122892305257844 MSE on training dataset: 0.013608856985103421 RMSE on training dataset: 0.11665700572663187 MAE on training dataset: 0.0781980493732077
for i in y_train_pred:
print(np.exp(i))
128966.05444367189 208206.76687081772 274520.10213752516 227055.52430423358 157620.3312142239 203486.6048119059 123311.17173587829 180952.9142025229 227519.44184347914 131853.69276232796 166215.7965893261 123101.40938621352 177622.51609312906 243569.9547447668 147252.66494665912 86734.89096827968 207814.06600087948 338692.1024370229 302446.9969542423 243668.56190705576 171422.51951022423 137168.72362794698 111811.03289816197 171498.59085370944 199104.84741303686 157785.5316022428 490564.25883710175 194742.24655291415 191786.32361771745 91000.37394686985 242144.30974585176 110165.19783831722 115734.15582125756 115191.55479136505 113273.8681844129 211526.14223943718 257888.03493959073 142700.88636606093 126877.85129425545 125823.68644795723 210302.56880101754 142547.4926932351 176568.5664515197 152882.00814444738 121707.21695151419 223607.1853257251 150295.5514356801 157872.65194328115 94179.3984390383 171031.54990296916 368521.0619235705 243808.9953803845 210164.39334370792 197752.062190591 296161.7536445439 179418.20341221063 165845.19105197294 220980.47670904317 91693.61397651717 75756.83677336275 167128.95157895432 401885.8956597288 93598.2263589867 111903.93902838267 144380.47903499435 166675.41477077064 142236.1074351601 199556.14066941055 152728.28196951866 224562.47699881066 112844.0249889477 195116.24390063394 69392.56809503472 152910.93051597138 273013.3728481435 113921.39961418985 141680.77505778865 221524.36340046645 106146.0172538931 230617.20892299633 172625.58272171495 147046.53900362275 187838.9953293562 220393.93926681313 90542.02790324634 204883.02481685614 198320.58939521312 160043.48787619043 138009.467742248 210284.74718719648 140567.88559310543 281874.3399034293 324890.5878301775 238723.8020595799 154131.54590186858 321639.8889266253 144917.35840372762 133733.09609842615 129109.11718168386 196794.8231735069 153192.70812424325 141763.34171582924 155868.94411280286 306950.1891557019 249555.1691165953 284106.79818530474 259576.18804268332 138645.51326999237 198420.2719742688 162490.38221622744 120290.29170704974 403505.83447911555 115902.19099801063 310843.9156398703 99005.2825508583 159166.19871221547 185357.9238220019 68568.20615205039 141547.48691033397 198375.01111633377 246584.1772383856 160882.67871222584 262915.5828077017 129289.31017987755 186208.3579266168 323793.952485735 150379.7428984989 338461.11602887843 161995.77197290826 238071.47649035856 154687.84648592488 157929.7967071134 82037.82509494643 205907.98693082482 93875.50383691657 136024.39010857238 177522.28395199875 244751.07572246875 161597.25292652135 245999.5513655138 245039.24965392606 169004.53444684696 198823.22808513942 391029.95702409674 141844.77097458782 175946.1254873918 153279.90148690072 187854.49844963124 163510.66838776827 220066.94966785156 141086.477533727 104024.73876420033 83709.28156728782 158845.17456464565 121783.80948687765 112976.01326035753 101394.47723767819 193101.82402479832 113294.06753504871 199700.1915063781 300393.02811452234 213907.20116373076 196055.7844285147 118151.68707252748 127338.22480096824 170145.30364338055 127678.77515967301 287514.0224983935 197154.72612057088 154279.31623302647 124074.21279235583 251438.52756378744 118361.35690112326 157552.95546553077 91009.6056220856 223331.1937328137 195884.1761506873 136788.99159447406 196227.84981789358 186065.31900901804 156264.09616010118 120507.39336696762 187703.25104633885 133344.46034228464 221411.5837046505 273414.59250400506 138243.28974167613 154168.09967589806 237002.61116090548 193130.33270678407 130098.73656310822 133922.67294745977 291585.92961627035 173238.89172057953 224093.15011155908 208900.51227792577 181337.45082924844 205040.73117555364 181745.097268843 193652.92944206658 200232.22110693782 253277.63878452982 382872.2736062026 205128.0950232365 246370.4036659686 95646.10118143426 415976.46369788965 172937.1849757477 100274.05087843077 154367.68998769863 172577.62907602405 107604.81497118628 346203.18646553566 201846.81189579048 160820.54421833664 188782.43397789556 285812.00686460803 183631.01795020915 510061.9206549179 99132.77935052183 131468.2627014273 139827.73179003331 166717.54229004474 55293.98347272086 160402.06816405882 169733.39017890568 133535.09891227484 215443.2156863576 173163.16613421822 123625.56954627248 165758.52506450075 141262.42058214906 168118.40663993635 198236.8380706108 122822.09598475265 217932.17313006756 305562.4983619129 233482.8903580817 177170.25112964807 181730.48116851106 135828.3248253727 370809.79961363727 133600.12797227886 149297.10414519874 169522.61795335126 115921.16857102736 242750.0923904967 110045.51908050576 222931.2666656207 134931.52149039696 173073.9649192563 237490.7217667202 257433.49600851178 177379.06997183885 183704.53611638094 298921.35332253313 185862.24351243433 157785.63606245565 254832.39294353442 262467.08467880933 284818.55971934245 363762.9404445376 114821.16276081835 193230.88920487213 103435.66426356674 192301.62289017302 224048.22554755097 206997.52661709036 114736.90870273596 293715.6483379167 122750.73652928851 134553.59487882708 122846.37688104197 81629.76018261447 92316.67425079095 309310.7826911304 132451.9572864124 267296.4129697268 219328.76376073496 129289.60442630341 178832.25234036273 191391.88926585446 94213.41592859568 93394.53614172235 191867.22184627148 260312.6188592123 142590.10499889695 92082.72627702483 250765.4887101852 291108.6204797058 273513.17008480715 169114.74842419234 126550.66059385329 188590.9803618697 220653.81555790285 173640.11644220602 184839.47715872104 120975.16466614262 149159.50786661665 168612.75076115725 144523.34337707583 120468.03068500488 160593.5430968936 156600.73649301892 118410.7360690458 178080.68730616212 260377.4539807107 250861.83656789287 192297.3701725937 84203.16513603453 92202.91281284405 224942.88647243532 184110.46625616724 125599.1761922822 336227.5757339665 172000.79888605175 156682.1325947711 168210.5492515646 168092.89347810153 231591.6906725655 220947.35120645273 164065.15538598626 156142.69406414838 108571.71396793169 173015.01189911674 171594.49462412327 277732.148567936 219354.84732545135 191893.83637370143 224662.90652293418 263181.4267577853 111519.54917366791 126952.10418729595 109847.1628173803 125143.21750778727 322611.3845502836 125003.24785445143 77877.78272391175 134858.60352868808 115888.18933988552 108862.81651668328 202920.09280985847 219598.3180713127 140843.9531712991 390010.88949262566 137384.2057693384 184853.17165117757 112282.99373816246 534450.5530465221 130108.20538457303 231395.15786645425 126460.97947586699 269726.4397587038 136473.21244693873 208529.9854425576 131089.7333521358 192623.7894847842 132837.6223246956 206337.33131220881 235641.7949874274 173943.00593178513 115801.12176235465 125342.24531393698 193799.49154929083 106238.40815411392 223294.9652844677 188909.54375188224 118038.13446538738 210298.85311094194 190369.54968515426 207757.72613901366 132716.87044963634 144372.20510944145 155156.42683849478 110911.83291702076 92323.27753259255 190539.8941747586 139812.97199354056 261485.48821248306 224783.5195880662 91215.7866430879 126683.2593936141 186541.5703390922 174371.19154830108 129052.45061092799 207422.04103392523 222839.27942949638 160706.81304427932 170602.36927629166 146794.9999037213 449371.4216975262 133309.94967214757 535246.7765199651 278023.1839565548 79096.69014836638 112110.67377901201 197399.1069549808 103908.0527174012 246384.1290014494 120144.51143533851 149099.41218934514 122939.82754195908 186136.91564584308 229793.64231663698 111557.57169941653 184081.74146973455 103571.72842477758 202887.82245459597 215186.80018281768 131023.5069355103 141048.4288310262 278624.1739725228 188558.66790684083 182876.9430895048 135734.46276793224 139979.96586406388 121170.60642326127 169626.59793259902 86215.94025558319 209835.64450470475 168548.27747848595 197767.2229398421 155304.0542812073 139535.43051914778 151267.96891084342 190591.38772924014 104265.75822110046 160162.46456358107 142918.87141698136 179638.0046912735 212044.7298289591 109489.77728991128 103224.51746102313 243264.17543423703 178391.1788845877 162080.33571452912 115090.76909161349 111972.71430641784 100860.44805244538 185726.20910833622 314245.48205969983 148698.43368578542 129776.73084617428 255375.40542416024 251800.5950398256 221536.68327321898 440705.91635380994 214638.15105386512 153549.52715288533 100975.66130737506 282930.8041925073 245961.7288799237 149855.93700271196 121809.66092512268 65754.14428279603 245563.20519806858 186734.04554434805 67742.36995646232 353171.6381595006 218885.17141364017 199841.5884243994 153564.39480952 182321.43162649413 179561.79458171577 134664.37049165712 253789.86133677655 80403.81301933824 61382.74043274725 221667.691379963 323497.7224227685 194081.83093044788 160676.94087735997 199805.87382752646 275409.54262246005 152456.34054335544 95510.9645264445 149557.93235689812 141217.1197032026 91224.65641010639 127256.55568457494 85414.84863799518 168539.19637126385 162294.23248799916 219248.32538887887 224689.41152913155 144799.2597495669 238064.275725467 151023.68777356835 109725.7494048672 169887.1040598677 317759.6685878254 402324.8075805367 143593.19289347564 297497.43253999023 105368.00159387237 128614.56944672602 248907.04076375542 262648.59325915115 132268.82743783106 265833.7616933238 153979.69398496996 252668.28183164966 124278.03624021138 160463.26531042898 159029.89541422974 62592.08456291589 79884.57695546557 111432.3915053308 132903.74668838654 173288.46230567052 122920.59195528153 140929.2674505048 197285.2645686441 93280.63785152714 117448.63445833986 157171.55629571114 229775.805089908 155288.51646062374 80089.20569079088 100589.01127995717 165559.14591700866 101935.38754879183 224748.3838374709 126080.60283079803 152289.18091809071 223874.11388477572 153039.4318765618 181947.8638451251 112527.48142477113 81435.7936242015 177181.57826546283 143919.87270854352 346845.83761667676 102454.89719202793 147445.75590877683 319046.9535954693 137023.7096844034 131667.07394808138 93082.3617273828 109418.79778839742 376494.6375147316 211139.79371911 125413.25087095359 133274.85651463576 93653.77693313672 149348.3942384414 152650.4693263111 147473.6324126997 132773.37812820097 128322.27312215033 287055.40107683575 197331.16090430747 129350.89281306778 216450.9854764668 293785.7143287247 144971.66898634934 197210.8020557071 189561.87035542502 107769.90084008375 142821.2170145616 79977.44475337648 145224.32168225013 122430.90902210724 116643.35781015774 149546.45335781615 139070.56906196734 57029.76552020144 256328.75792546492 94158.85058155548 202656.58395943386 194225.81419719273 108324.93306539935 344454.4531864561 146506.23382523307 143928.56938373542 197659.97352072995 241652.73066165613 215175.6170362074 127353.24562241047 134682.5668433751 139729.47738048207 221112.2796298336 100411.67972311431 116956.93453148672 237612.30263611907 120333.61232845813 278319.2787268509 282710.92412989435 137162.71793460436 378645.9180064721 127972.47198749357 170626.0808963302 158083.3745476458 136123.1591890432 123848.238950891 198035.34450124227 205924.13947655016 292366.7641864476 170432.521424668 124639.1663367662 229250.91071489418 261378.23567746856 171852.25255526876 86660.18209395347 387486.7476819473 218897.22562533306 226997.64920823305 111827.15113919051 107390.25363742103 189677.393462601 139663.16814262897 225374.7161386943 176029.29344965666 255437.49504699165 214618.8343555706 95735.54294907195 343446.5295298786 88043.22415769985 146519.94277090393 163509.154058946 97594.72914806734 167546.39518890242 160837.75385243076 239082.13682617107 93633.52824078451 130780.01490733886 212281.83439924748 138434.00682474478 140623.98731692156 211807.77836431572 180382.12178808847 138326.78797402355 140466.8898028088 173906.33799987225 197716.79964828165 113603.83519100102 116993.01529774831 137687.97220108146 318594.33702977933 176484.35144309292 129566.93403413665 124647.24435953496 171482.36575619358 186218.22770696747 146722.15334836624 182070.1679567789 177660.90478947997 98474.96336081823 95207.96453889678 101822.79688203816 205700.50794120575 247701.4998259111 257866.81196666392 157831.4229130984 180857.56576319202 140668.4032965731 110451.3579711461 306841.01431493025 128667.04959330351 378339.1655334153 137763.67846848862 173896.0869598955 110000.34067017284 197671.1205183214 245568.61285681662 130761.41820692587 103646.3770056079 136418.48527226216 276830.48882179416 202129.48340145987 317518.0147351404 109338.92228618037 125676.67749095258 168968.37984671493 126235.55144771961 261832.7744535573 159832.3974291407 317099.32852359355 218139.4370188822 173163.7341847096 131167.76718527923 203772.1860672275 203738.09747108296 334839.5447452317 132232.940108945 209752.05073408733 311002.0761173652 191913.4667154914 208258.3915402366 163867.29851604844 162871.45366147495 180638.58444132484 119837.5069251193 168374.12728081507 116535.82472223933 200548.84826583485 217587.84394887846 125416.78659390195 99502.6915525946 102000.08797571836 240382.23249020416 173871.16908205935 153605.79751665567 206872.2678994608 145634.95798896765 158387.1895120634 110435.45596752461 88117.18064227284 181653.08204326904 186196.29461496128 134439.602233577 288174.60443578765 116825.85688303022 211387.36788291522 141559.85868638323 71626.49182299206 148928.24610430113 166631.70859854497 248620.8763867008 413035.6084799015 196562.0977416989 144553.9112061217 149896.73386940235 254093.1188601329 125886.52625765867 215097.30865500745 261955.87774839444 163793.42013172407 107798.63689953148 181861.50233545317 119807.88785863674 154602.07179090075 204583.65029666977 122340.75795869391 174265.01143745292 449791.15608376777 231998.42375991395 103012.38957171809 97365.28381349905 137916.33555703258 121217.44034012231 213015.41109287777 197282.45251564102 145278.34336173758 88579.02134077839 140049.97043057432 175423.23242801792 202806.65114959693 165946.96975167788 157636.9487913459 182689.5999185939 248753.9851437469 118540.19659393215 222381.66150883934 235629.78075445784 237008.75773181103 220640.64649962363 169802.1452924192 130485.48182677 99476.4037538674 90854.58765460826 213134.8143711107 363023.30279903085 155189.63412779657 180854.63137693223 216448.8196349147 133731.26913992467 98007.1782148693 195510.41290336545 187071.11843216256 118889.89153344948 69810.54616740714 97374.57672897904 300177.78134306567 317486.80374847515 247914.8302910967 126462.37334325377 131127.93252188814 228932.86244568118 96445.77776061803 137071.75425731964 113400.32470918074 140291.2529489134 223435.86511062997 200379.52408236795 161211.0498638821 85979.25002239061 94527.64067481781 150147.90922862687 125374.37036577563 164955.6111069762 132939.77812810976 264168.6331365024 164241.67835901317 135294.26451561908 140306.44105331964 264923.4620171985 139176.30033554867 241851.48944777812 141151.49765879902 236951.04633155811 129790.96823440248 80285.73165534993 174823.7601452368 113388.40242093065 109549.0186616094 125857.45006031761 103295.9102584346 159372.26742402857 173997.61100759314 187946.67784673072 181005.4487985337 205777.75623617586 352237.1959319177 218844.30627847704 161805.2451359751 322198.06731389795 214394.44287302013 120550.95912724223 213891.2670694456 219535.55705770437 187000.29092522268 244799.32249059482 135789.60667833907 206854.7718155482 121785.01518622115 130014.50012262243 132370.9139913439 254796.33546784008 243898.43486703487 116505.82103132438 234456.87451545926 254252.27792552224 171755.5224339835 176941.78944714225 236370.88488855158 186755.41577006853 335975.37451901654 143393.67894700836 153856.74131132095 121110.70588011688 129641.11321301528 275653.3049213872 96526.42948659067 118600.59005885597 288651.8600132386 126715.57508499417 189605.68101829823 89722.72842525301 148850.1543895256 261267.1437821498 149972.53417650526 119712.21283507241 160536.72707931531 123782.81270549998 154693.75715471775 168787.13952405294 142371.61467650556 180833.8628611994 186897.7024592575 219907.95778171238 171630.88526531626 143993.13400202684 167156.10880531443 139604.93298111655 119227.94327566889 153049.47968238738 303053.29979658744 114206.55103839227 127161.23707667162 284657.93004509446 195636.81299362297 311547.7283010794 147327.8760237929 247359.363952098 169306.04063954038 133361.9987987427 184644.91134768448 149904.13431901103 161361.6110367095 162534.3092367579 174490.59955869036 138588.33460641894 172893.33290875182 91368.47519964514 134268.2589659183 110364.20472511307 205580.41501879046 94503.82999779389 136175.58401551377 190166.9208806117 158364.76718414348 237132.49581038102 119253.32262099966 328378.42283693014 249409.52378851027 125900.17661718544 118385.199765416 280880.91741943144 83301.7726168551 103993.96472727065 118259.75361983832 135590.37678582539 149352.0940572155 221864.17668121128 207576.12114431238 146720.46049161098 126200.16092193284 169717.4288657894 196422.48132367316 149839.4296217 205444.5787417752 136289.68893953352 331960.778606853 112778.16966716267 106829.70504394919 222725.2946786693 142863.0625747932 129386.38975808106 93016.66529241047 151651.97292369412 215029.87466005416 90288.03764245925 227963.67358171518 147511.54197485448 214039.34326103213 156290.79822933127 173010.01023174945 172024.40184051706 140745.41323725556 313961.4825021935 210206.80695720986 159650.07871025224 169941.43454786227 137711.09965555262 213862.61424811388 142692.21879521883 154309.96135996736 229856.34799263542 129642.50317658542 169247.20900419494 238506.48064571718 195424.59642397362 155763.03991186505 118700.01695855508 164797.70065492106 391366.7297138942 97907.49723568815 205833.6200800778 345252.51972608065 130843.27753688193 125251.41539294587 203591.61925773957 129788.74798964828 107044.31274945299 189657.69567719536 276407.8317884868 155375.99225239342 175654.85742266764 148914.77025401505 210152.15069998652 114569.75042759217 171823.96649315913 143600.00270544586 276643.13822247344 243884.6820329833 227224.7252593994 97908.70916968673 223075.77368235277 204553.0214979989 280049.44303191785 137454.24668925203 145873.88119702996 188237.9826462497 137610.06170822078 327029.76443560125 107137.26317805986 225562.36757803234 159619.56005935397 324374.54062057287 105039.43655230761 140171.77135952737 215223.47196973482 127194.78671350704 269683.301051094 175530.33248828817 201081.1673079819 157706.3239255567 196900.19211652258 246221.04966861458 146349.67683088724 213052.03809390715 175879.2879016242 131786.51070902892 59094.17410068538 124161.84485611365 197689.2648820829 192134.7348651203 157391.83678303089 113380.41549254909 202334.63908880833 207134.8773256 347633.06034019514 280665.0191870263 536649.902599767 109669.08242013655 208380.03483835 179879.39998477208 104208.72725154947 149114.96086541488 158018.09367489026 137011.4779770258 146129.27843046683 172761.44035668575 94349.00469023515 299794.11297981895 184842.05897633792 140700.94763000964 128975.69450352543 180181.96420493518 199668.045764098
# Evaluating on testing dataset
y_test_pred= lasso_model.predict(X_test)
print( 'r2 score on testing dataset:', r2_score(y_test, y_test_pred))
print( 'MSE on testing dataset:', mean_squared_error(y_test, y_test_pred))
print( 'RMSE on testing dataset:', (mean_squared_error(y_test, y_test_pred)**.5))
print( 'MAE on testing dataset:', mean_absolute_error(y_test, y_test_pred))
r2_test.append(r2_score(y_test, y_test_pred))
MAE_test.append(mean_absolute_error(y_test, y_test_pred))
MSE_test.append(mean_squared_error(y_test, y_test_pred))
RMSE_test.append(mean_squared_error(y_test, y_test_pred)**.5)
r2 score on testing dataset: 0.8950229007608679 MSE on testing dataset: 0.017769092377509992 RMSE on testing dataset: 0.1333007591032774 MAE on testing dataset: 0.0923855598882854
for i in y_test_pred:
print(np.exp(i))
151867.56477957996 313575.0164873651 98220.43719605358 153279.2867311146 317341.2137051542 82917.46092957689 245611.0235329899 140499.3291210323 79891.68132671695 141332.71085340367 144742.1243881481 122123.38821972009 92237.8699148967 218486.62095497892 175442.78224572935 136663.0266465386 198361.18035534982 131001.41202858946 107574.88286030733 211195.8498467439 168109.92268771908 205681.386776068 187140.847913331 136764.6311722077 199343.4868495306 154866.6834451124 197257.79056119782 107643.42857021015 173460.66894816587 201209.26374657382 129922.99765054611 279593.920879489 196497.34698466476 109230.71888534036 273693.0529531759 149856.8502158368 136811.2873302936 207322.95770896223 330761.69580954977 107071.26022973155 139570.77899725782 235348.5569493612 114422.67472688916 316372.6655116767 129784.65215732185 132651.91034275628 111482.00769496107 131772.36068381602 426375.2582842056 120428.3442806038 122236.00779669017 200141.34732800012 107664.95480231773 282536.8638799721 160155.46908042114 219101.168006188 219170.82540326417 159586.04611178115 138578.20193345135 110955.24665260056 72703.18317626341 169547.51630528807 307723.6022366916 248582.71951883571 303511.8874817752 199420.99503847933 105319.51519009602 313599.85947761615 114267.26424829944 167396.0375561145 125740.57622825041 124483.46841044017 110041.89887921071 84571.64536591401 432346.759440454 202251.9201643859 291237.8494324643 316175.0261843128 147439.73658406394 115149.15738173567 115988.19046435445 72549.17290141147 112789.42907792497 103692.2423167436 161534.3205105404 124804.6542213286 262608.3568951328 224873.6121326141 150059.55138402956 199679.52261159176 120195.68061336374 132570.90582159738 135579.1154309972 263345.2937366388 102752.6511363388 184279.1591950292 173158.31672039424 182566.4768010959 195295.93360166484 266213.98588597984 148581.15841946992 212293.38880863806 237732.29301373975 138438.34698307142 177978.3075917538 184219.324600398 163091.1524630311 283372.4213542233 141291.91636232575 197610.22846656025 56549.55739126374 114600.96915236741 144044.5640501339 140189.0433557172 199275.17225748755 112401.77256854835 106260.12840294198 121694.33478655867 127780.134355992 277251.81327301095 132644.09958858628 148161.72148504798 178253.8457883581 189175.4670156891 181114.0546108714 134672.04992654664 230411.69101752678 94472.82341317648 147038.39116372084 199459.09525842543 191983.6213133707 321180.5791869427 188561.37361278737 122664.84451807202 70959.74478253907 372600.2744547634 329129.52234660747 137102.2233879104 219506.72019349123 586319.0376395289 332513.4157817163 131629.4649007834 172416.05684871366 155126.10115419852 123767.06148369783 127608.62333430743 246077.91779738566 185602.1211854127 124146.6178980655 67674.26123694837 119434.90988753176 141238.54354154738 237896.16613418178 148558.81771820356 73379.84238302139 121113.32747346676 119289.15649230286 139461.69629695668 90750.36185368887 135194.61606064983 201496.16051609314 127542.28414829425 292412.3021681539 137458.65808669274 112374.69330349349 115492.79599193239 246310.50820474455 294411.36778966524 436011.73964356456 214369.37668593234 374778.4719929739 88357.29987062425 110397.39729614886 150092.465104742 300525.0082621423 114969.67324027189 121757.44375964873 212526.07113402055 122575.3075476641 158191.49548227072 196146.58241848968 106346.46734693712 124857.71508026622 144453.43727862212 250159.53449359193 124418.91133284006 274527.5395474732 223679.76854059476 203913.41876713102 85660.53078858045 111636.82383230775 98739.18308876372 142078.33929211233 133605.2223148992 196072.068639007 166172.5284010004 216424.05065957477 96576.35340665984 209988.1009047809 140875.95563637966 229843.41211383595 214359.8613370173 112668.04623721712 304634.80680062086 200411.92623837784 123124.3536892239 233041.49005747147 132076.60314962166 138689.47232219912 112542.29875815185 230949.15228242674 159574.09308750235 110738.60706605611 160895.54916199035 215384.58850042138 241209.466196324 206449.86364091406 130811.92942957123 119128.11346550296 133826.32632611683 142196.18048845057 233920.55923129004 190891.29605073793 98559.62737293438 231058.7241371207 138099.7697929118 97589.29525165135 103518.12431980805 163839.1409768653 106446.01446594998 101320.50807101848 175727.9227037424 126529.61867129449 116067.90550323411 233725.82733703434 140860.2619650036 201351.9082532106 158322.05385379776 234161.1838317766 131642.8558354805 109971.84060853969 250206.92931325643 222513.21890179897 483535.3785946369 188374.81351387643 120384.49587357449 146613.26946779928 171282.98902912776 141586.9099687426 103191.2958899197 159819.33963663506 189218.14343489494 141513.67987069293 97441.72468062381 144918.05219823925 144806.8059240995 115664.30102915381 112353.52349507893 174118.36410931667 248063.25369373595 291913.0767895879 179444.16546611174 130088.36655457242 232664.03315404474 314564.2549247673 225022.90091565784 152977.99703826997 141067.4638438407 118946.31194310526 193667.6755648981 406826.7691452497 240390.67010536516 237228.71836625572 92741.54567151306 104109.9943150872 133832.7927033681 134601.06684070357 275281.2621487855 211987.38192677445 130651.81299687397 207217.6467171189 91800.15587004476 194385.44498231402 112982.27756904568 294911.35303515923 178366.09673198982 208006.58447137053 111889.64860917047 256375.50828858235 209466.5329760599 111044.30677889612 120272.13099538928 132744.4549973532 183066.42165081462 85178.38079784816 154052.99797176514 161975.44942670062 140879.33605583978 177399.4102604113 117166.77489207305 181466.67670507598 222300.31851520555 133975.9278009153 134540.94377813645 170907.75822639337 202335.06522667935 149582.58843473071 209736.72081261504 209745.30168641967 118260.99181279777 140078.93474267604 170714.12108555305 98065.20342074468 205167.74537260152 123755.0290374732 176350.86952621 189384.2249656377 170111.57785900435 289339.0404687095 83439.56853368758 214348.48382594038 138284.92098726876 137231.68979644604 83667.13131595613 192351.81231746287 142135.74115665132 136196.33358350472 220477.8010986316 151279.28564493725 102850.39740535154 135907.21226145103 143122.34105363057 148247.00806482194 202196.40895326884 156652.50112378987 125289.42051801668 161549.46304871212 89219.39392079443 81143.83595067906 199279.72071933906 194426.8395551972 145047.2456241951 129727.88846363696 192230.8796755299 233131.75037221765 356068.7254936117 358254.5410358476 106246.37333752755 233590.27514239418 123971.08610153521 244069.42254944396 337677.6711180453 266324.765561922 176106.63116174605 228596.92435774204 135707.3789264614 122438.144291915 86203.74067534032 214712.20282655995 330489.208749718 189803.08402673027 124741.58119488427 231822.13322590885 235214.40453359237 128241.34630904974 189321.94944344953 158806.6333519834 112524.50829500695 123295.92387766084 151369.92287137033 119525.5893421724 179118.57866621338 118913.2123352597 202289.3333921115 178398.61021128905 133880.607380609 222793.67106282568 188780.4098235699 95559.15760094367 208138.23310760516 145259.69588686526 173733.8317354475 195465.51655591422 159489.73178654673 126044.80803230173 233629.2396873605 137582.86830251548 115687.48916364509 264686.89444190473 176614.1025550146 123257.56363697747 138468.33726858275 137875.43682191742 347501.9811946846 138651.10172033077 417797.98863935214 127850.68313410315 197038.9618975747 171237.8710339889 127006.50530212045 169606.22841607756 375917.84613559383 102912.409320999 154278.48272748885 142768.04160742092 101416.8759551442 191262.22766675122 131006.27938638606 219641.34372539536 214607.62061067266 242557.87806805526 214689.26957675844 99519.66569039927 318411.28090736456 150818.09849140138 332593.2561280573 127390.28336821828 353455.91974576813 261097.25978379353 122941.46601965665 215735.11681254362 254138.71809421014 216769.67152177918 175980.34559071588 266171.14088138065 120168.5875986118 228429.21614140156 188382.06564563676 213437.40841552423 226872.1151339634 118806.02163249465 150825.2823454288 161978.07108223526 131582.006259392 122324.17793231644 204882.82108851848 133434.80712041678 410072.7603351436 185563.61820440448
# Checking no. of features in Ridge and Lasso models
lasso_coef= pd.Series(lasso_model.coef_, index= X_train.columns)
selected_features= len(lasso_coef[lasso_coef != 0])
print('Features selected by Lasso:', selected_features)
print('Features present in Ridge:', X_train.shape[1])
Features selected by Lasso: 111 Features present in Ridge: 228
# Lasso intercept
lasso_model.intercept_
11.71667710864116
# Top 25 features with coefficients in Lasso model
top25_features_lasso= lasso_coef[abs(lasso_coef[lasso_coef != 0]).nlargest(25).index]
top25_features_lasso
GrLivArea 0.327289 OverallQual 0.303682 GarageCars 0.192959 OverallCond 0.149110 Neighborhood_StoneBr 0.134646 YearBuilt 0.109206 Exterior1st_BrkFace 0.101865 Neighborhood_Crawfor 0.098681 Neighborhood_NridgHt 0.097413 MSSubClass_30 -0.095560 TotRmsAbvGrd 0.094190 BldgType_Twnhs -0.087679 BldgType_TwnhsE -0.073091 CentralAir 0.070966 LandContour_HLS 0.070444 BsmtQual_Not Present -0.069620 Neighborhood_NoRidge 0.067973 FullBath 0.067666 YearRemodAdd 0.065814 KitchenAbvGr -0.060217 BsmtExposure_Gd 0.059748 Neighborhood_Somerst 0.059742 MSSubClass_160 -0.058783 ScreenPorch 0.056547 Neighborhood_ClearCr 0.056043 dtype: float64
# Ploting top 25 features
plt.figure(figsize= (7, 5))
top25_features_lasso.plot.barh(color= (top25_features_lasso > 0).map({True: 'g', False: 'r'}))
plt.show()
#KNN Regressor
uniform = []
distance = []
r = range (1,21,2)
for k in r:
# Euclidan, 'straight' distance
model = KNeighborsRegressor(n_neighbors = k, weights='uniform')
model.fit(X_train.values, y_train.values)
uniform.append(model.score(X_test.values,y_test.values))
# Distance is inversely proportional (to lessen the weight of outliers)
model = KNeighborsRegressor(n_neighbors = k, weights='distance')
model.fit(X_train.values, y_train.values)
distance.append(model.score(X_test.values,y_test.values))
uniform = np.array(uniform)
distance = np.array(distance)
plt.rcParams['figure.figsize'] = [10, 3]
plt.rcParams['figure.dpi'] = 100 # 200 e.g. is really fine, but slower
plt.plot(r,uniform,label='uniform',color='blue')
plt.plot(r,distance,label='distance',color='red')
plt.legend()
plt.gca().set_xticks(r)
plt.show()
y_test_pred= model.predict(X_test)
print( 'r2 score on testing dataset:', r2_score(y_test, y_test_pred))
print( 'MSE on testing dataset:', mean_squared_error(y_test, y_test_pred))
print( 'RMSE on testing dataset:', (mean_squared_error(y_test, y_test_pred)**.5))
print( 'MAE on testing dataset:', mean_absolute_error(y_test, y_test_pred))
r2_test.append(r2_score(y_train, y_train_pred))
MAE_test.append(mean_absolute_error(y_train, y_train_pred))
MSE_test.append(mean_squared_error(y_train, y_train_pred))
RMSE_test.append(mean_squared_error(y_train, y_train_pred)**.5)
r2 score on testing dataset: 0.7593989113518294 MSE on testing dataset: 0.04072567256387984 RMSE on testing dataset: 0.20180602707520864 MAE on testing dataset: 0.13836867552595092
C:\Users\HP\anaconda3\lib\site-packages\sklearn\base.py:413: UserWarning: X has feature names, but KNeighborsRegressor was fitted without feature names warnings.warn(
for i in y_test_pred:
print(np.exp(i))
130263.92352517834 274392.68462010636 108485.03108846341 125486.17853290921 301244.88959496154 94594.92632276706 216357.774785413 154473.3495359899 94341.08676923535 123782.88996087824 136227.24869205547 126857.33831285939 115893.88320380231 205650.84513491546 181919.29059639561 132448.61612708136 195267.66820962538 133168.96849925566 118831.81518609506 208121.30824092345 150185.5111954182 205217.09989656997 205789.18348780726 134192.72422949356 207186.53445732113 196000.88212496066 202779.68865479343 118559.78137715926 185468.32485129035 209529.56966425598 123043.53654160627 253824.59714702718 128811.68955056902 120744.88757976884 234176.18916300667 139250.188540382 129972.68135422784 212310.79349667983 235383.0745493509 104911.27440675284 125387.14662035879 211562.05661863319 122481.96713652078 300134.5583426642 129837.22317936619 114419.79137813482 126456.17637647326 125545.73597697764 350415.09496315056 136341.27456657495 128536.56782383415 197156.13896472045 136422.53783765147 258228.7554054993 174668.6399083254 211215.8986355976 224973.9482042791 180647.20641859504 144480.69776920934 106040.61414428064 107572.62115671708 145186.36395787448 265451.6607077129 231814.79880823326 274730.99413890624 137393.91553598703 121391.724584503 273100.13867916376 109366.57564300479 154343.62081506551 111616.07451667795 135928.95465107364 126559.01433180475 102509.49684971894 385040.465223579 210703.54868915706 263574.74911167345 279712.9300670719 135949.7562370697 120574.00768235086 115417.6392392647 100627.68001635614 125357.83103832473 109943.28235501713 169095.2318825413 123402.97786152469 221238.6572316845 218239.7551278697 173543.7701657609 194505.53467648683 115769.6977273864 160616.77100938922 129238.9349977062 225615.86992102597 109320.66556917729 202727.9170575034 129216.25677594451 179422.84537016822 211852.82460193205 242568.16634692697 152506.95633744728 212674.0863497485 185540.32616815952 115163.71769101132 179057.39906062814 161812.4406082581 137486.5650846205 226154.19778086175 155921.2777623464 213831.2852890683 78288.57558790571 107273.673268038 126863.29997658497 121503.47485913758 193862.542198858 131114.4316347254 116142.56199793598 124219.9849739887 109217.1611211516 221021.9543030447 158282.3466772774 171486.60997007377 185600.8898693412 157996.76022734147 176961.52409546258 129426.67107878074 219865.32711641907 123123.82424246673 179798.48027079744 181631.37785182436 203707.33298299104 301409.40906642587 195143.36741520837 143514.66472347296 115478.04497946028 347137.286385635 333248.1016018266 132338.32378200383 224903.52507463668 325931.98524975224 269681.30617924465 126602.26561209057 212635.79663618043 135765.30178141742 131299.09901785105 136602.9368905479 180448.94247247916 200634.0322971917 134284.33974433786 88138.35175674423 122912.01883831748 156415.57042233975 226873.20042956027 140713.94241959875 114127.58130645099 126310.56429728131 139288.18547465478 138062.68519212233 97042.09827365185 141476.37058298907 200032.8773874487 135838.79098881697 281403.0563083592 134530.85594667238 124645.54353544628 110622.29270674493 261024.699720477 291290.3456640483 337721.28487453103 145474.35530942096 295717.5838702669 97743.8221817952 135085.38833716247 130590.5009282094 265116.2252866836 119418.90324566889 121648.02932882638 218320.70522276493 118356.27542657785 171696.92741231207 184566.8277357928 105498.4545478187 125408.66003839816 130657.43058438327 250987.5293939844 128955.96282364127 275747.0954085227 228342.10465179075 205973.25634844965 102017.56982117942 108616.15860608616 112194.69387104831 136770.13450671968 341498.3009930766 216430.1952544836 131980.62193843868 206930.6422770926 114255.40375680238 183618.4725615771 142829.62774208124 193805.22446788635 192285.3968467048 123683.55253106588 265593.7603470749 204903.69182476157 137569.58350862467 222786.714210492 127857.3567040589 134812.39562182495 133393.89549939518 233501.95364329367 153508.19283640996 103434.99213875124 157831.2613160623 170568.06082371768 224764.01263867208 197809.12289632094 155629.57173973988 141820.05506688982 119581.09047606176 126707.51700282178 226301.66465116554 194455.39922168053 113044.34217687914 204223.2226138595 137083.81955869537 122281.41827377048 109636.89386296106 171416.62862939763 124759.52972334356 111145.06186702364 192300.13545196512 135031.63780509064 130046.86643876732 230559.5920236662 128066.51209261054 209956.30581298808 168680.7078915838 237828.46341032407 152436.38340493708 114809.346511658 227643.80313802336 214137.08637969752 286230.615143868 186464.86068989988 113254.98518970296 168711.12635192962 184328.97563642345 144728.03243703552 112041.18837405436 206246.08747711199 199785.27310423992 131857.1717310082 98454.2133359056 141460.87974278093 147411.93419445402 123090.70563526926 104783.4357518716 199202.61898118086 234586.7107504917 239403.89778723713 163823.90810813464 127939.49853195914 230217.39213789228 346407.27789697 230533.99804069666 170948.18647864097 151167.56078439672 127854.04160617068 188912.7718700841 352506.06529785896 232108.2037243315 224290.07663109718 112717.29756732911 112025.84898475866 129903.49683504016 138034.7406797406 265159.3023311475 164182.95456395132 132204.29007395866 222460.98327812436 101641.25715896147 212763.6036245921 122661.46637373064 272364.0950368569 159389.88980063077 207139.53985126928 111485.21619613493 278719.69212525326 212265.80830971414 129276.951197961 120981.7655296048 130859.1235530913 188800.0044646927 87554.55288089528 138510.36203234276 136268.92524022187 130497.17193978518 195293.69227992467 127196.12406531675 170760.74998638566 233059.79336276648 121213.01409986822 148783.47146365183 161640.03762211953 158187.77991161257 136078.76272545237 206017.5439815568 150662.28254541598 122828.98912025415 152201.42435840252 160999.03726095663 112294.76124580152 141004.35265782292 126506.47057432913 183970.5419769726 207634.91351726017 178698.85595608113 230881.7638555396 103420.74585785609 231120.44308954457 134335.89339532366 105208.19499004429 92607.38485684208 160100.69060323198 152174.55847187754 132782.20402611457 206117.1426109731 232394.35720422477 118785.15265221389 150097.74919638442 140492.7365502465 140612.28480849758 160485.79241892358 169858.51738642537 125492.74344485784 134286.2696325827 96998.91241811163 91598.0030847106 236300.66291986645 190051.4455798341 128127.18421319143 99369.78951027752 147125.1957188004 206028.89847746358 284070.1590438477 333647.22647143726 104654.1961597431 193423.29349479947 136587.80290925148 159529.45267525336 298889.4734593039 263421.1092853393 210738.6511879795 212169.86987734883 147998.48025250487 133197.13113022604 92294.04538939796 223174.04966276162 291237.4460353801 186947.30473733888 154334.28720458102 211418.62922669254 217502.29174856213 128272.98703664086 190654.36106088123 253172.316592014 127715.58371305917 148267.1384550845 140087.4309020075 123288.82466366491 183026.28041444617 122838.19191232411 201450.4868281442 143008.70242122893 123427.10045420816 177385.1115207849 173097.62747422274 107430.52894238813 199279.22419566498 137355.21057217824 146468.03739104306 194067.88188430632 153780.9412304393 126405.05676580207 237626.9910993317 134018.78568337878 109566.57353083862 220932.99624973556 153714.08778021592 123236.29970413001 129409.57165662911 148232.11147779008 319894.1758444601 139235.10151604374 369125.0128932592 117537.33260428612 153511.8043870696 197598.85158033628 149568.39500210993 184826.21469716137 276841.15655641985 89558.72763492927 137812.49777102342 136674.17163595842 108027.99530510849 185710.26122475197 134550.99928150693 173273.33205649914 215632.72471413866 234615.7859512314 229483.14016431491 97267.86630832958 316880.9161809277 130174.07197185245 291785.93897907494 136723.34303654937 299688.92993015354 227896.8686040407 124472.58003317697 226852.53782640444 238088.15584602146 223898.3282561876 177123.82087055544 226173.2718875218 105794.58973542719 241009.30404235885 181022.1138006567 204506.53048892977 226425.88204192338 130060.870054897 198098.4221899425 153868.64023444435 136922.2602633567 122169.05521571085 210198.50606031992 133956.384126458 346655.7750165102 144799.9033679391
#CrossValidation for KNN Regressor
pd.DataFrame({"k" : r, "uniform" : uniform, "distance" : distance})
| k | uniform | distance | |
|---|---|---|---|
| 0 | 1 | 0.688579 | 0.688579 |
| 1 | 3 | 0.748051 | 0.744032 |
| 2 | 5 | 0.762067 | 0.756299 |
| 3 | 7 | 0.768034 | 0.759591 |
| 4 | 9 | 0.775751 | 0.765670 |
| 5 | 11 | 0.773687 | 0.764302 |
| 6 | 13 | 0.771112 | 0.765221 |
| 7 | 15 | 0.769263 | 0.762941 |
| 8 | 17 | 0.768009 | 0.761952 |
| 9 | 19 | 0.764796 | 0.759399 |
params = {'n_neighbors':range(1,21,2),'weights':['uniform','distance']}
model = GridSearchCV(KNeighborsRegressor(), params, cv=5)
model.fit(X_train.values,y_train.values)
model.best_params_
{'n_neighbors': 19, 'weights': 'uniform'}
model.score(X_test.values,y_test.values)
0.7647962134922948
y_test_pred= model.predict(X_test)
print(y_test_pred)
print( 'r2 score on testing dataset:', r2_score(y_test, y_test_pred))
print( 'MSE on testing dataset:', mean_squared_error(y_test, y_test_pred))
print( 'RMSE on testing dataset:', (mean_squared_error(y_test, y_test_pred)**.5))
print( 'MAE on testing dataset:', mean_absolute_error(y_test, y_test_pred))
r2_test.append(r2_score(y_test, y_test_pred))
MAE_test.append(mean_absolute_error(y_test, y_test_pred))
MSE_test.append(mean_squared_error(y_test, y_test_pred))
RMSE_test.append(mean_squared_error(y_test, y_test_pred)**.5)
[11.77883721 12.52380267 11.59573492 11.7387911 12.60959677 11.4641086 12.28779409 11.95436471 11.46164892 11.72647046 11.82152507 11.75387638 11.66038012 12.2318138 12.11524215 11.79329228 12.19195485 11.79632495 11.68796014 12.23404335 11.92016228 12.2269022 12.23362148 11.80765431 12.24036218 12.18885425 12.23444849 11.68815651 12.13341097 12.25264705 11.71984453 12.43337121 11.86728373 11.70962847 12.35830043 11.84263787 11.77542781 12.27394906 12.36324441 11.56343405 11.88134058 12.26010234 11.71836017 12.61260702 11.7729154 11.64838249 11.74637632 11.74034776 12.76410562 11.8246619 11.76420838 12.19261668 11.83355454 12.46074505 12.0999207 12.26188974 12.31840703 12.10450898 11.87967321 11.57306255 11.58502374 11.88201536 12.47759403 12.35260292 12.5238024 11.83276037 11.70486166 12.51391966 11.60463103 11.93523559 11.61313071 11.81819139 11.7503997 11.5450739 12.8522425 12.26077875 12.460478 12.53762459 11.82096623 11.7010879 11.68988423 11.51767003 11.73970883 11.61201025 12.03957346 11.7204259 12.30319285 12.29208625 12.09608467 12.18490814 11.66008182 11.98425602 11.77117191 12.32097489 11.60565722 12.2196957 11.76562627 12.11658944 12.27014187 12.39772391 11.93217474 12.27847606 12.13544587 11.65458167 12.09734659 11.9921195 11.83296113 12.32862696 11.96560404 12.27375555 11.28198442 11.5863905 11.74944628 11.70937266 12.17687264 11.79096895 11.66446811 11.73011456 11.60040497 12.30201106 11.97371049 12.09455901 12.13402168 11.96841587 12.08476662 11.77095167 12.29707615 11.70028779 12.10951557 12.10966858 12.22472093 12.60373446 12.18467907 11.88611487 11.65688282 12.75763733 12.71715448 11.7990454 12.32778883 12.68380465 12.49070375 11.74574565 12.26816687 11.81812544 11.78490785 11.82679657 12.10301515 12.21419466 11.80874663 11.38901147 11.71945196 11.95662738 12.32916322 11.85542648 11.64828207 11.75211814 11.84336126 11.83642454 11.4831178 11.86249168 12.209885 11.81697383 12.546411 11.80814653 11.73157467 11.61716821 12.47002014 12.58214174 12.7239746 11.88429749 12.59278975 11.49390882 11.88891721 11.77844519 12.48129427 11.69383158 11.71048098 12.29362884 11.67583686 12.05932766 12.08450661 11.56824128 11.73940518 11.77774048 12.4343365 11.76991955 12.52568174 12.33983108 12.2322879 11.53703228 11.61351467 11.62761405 11.82435067 12.08713218 12.28676258 11.79059151 12.24037593 11.64624434 12.12871525 11.86829603 12.15952806 12.16754826 11.72518083 12.47333336 12.22685644 11.83456643 12.31667139 11.75965823 11.81061342 11.81830423 12.35996154 11.93881551 11.54970173 11.95778407 12.03834072 12.32190375 12.19898522 11.95585051 11.86180458 11.69260515 11.74756904 12.31508782 12.17897364 11.63410001 12.22544928 11.82593762 11.71341196 11.60548233 12.04917425 11.73507374 11.62057968 12.1694933 11.81497077 11.78187409 12.34772567 11.75677367 12.25946017 12.03389789 12.37861893 11.95263075 11.65203489 12.33496134 12.23972719 12.55514469 12.13575541 11.6354392 12.03457395 12.12647322 11.88347115 11.62829654 12.23885654 12.21246907 11.78545707 11.4950315 11.86046895 11.9108396 11.71894516 11.56987811 12.20574033 12.36174474 12.38612107 12.00451344 11.76160475 12.34736719 12.75411966 12.34907819 12.05812158 12.09681482 11.76001308 12.15046613 12.76907395 12.28075235 12.31654235 11.64803622 11.63761758 11.77719228 12.03502976 12.48726838 12.00505291 11.79313876 12.31682719 11.54589948 12.27388115 11.71948604 12.51253736 11.98222 12.23651733 11.62118578 12.52889412 12.26730435 11.77585096 11.69775059 11.77818046 12.15110684 11.38092813 11.83774754 11.82453616 11.7800391 12.18044081 11.75777763 12.04797014 12.35417635 11.70518368 11.90980481 11.99504089 11.97034544 11.81433916 12.23344589 11.92209021 11.71839364 11.932442 11.98587172 11.62957316 11.85673981 11.74412321 12.12962461 12.24114152 12.10431204 12.35026385 11.55728102 12.3506217 11.80931656 11.83268521 11.43754781 11.98408649 11.93220633 11.79552068 12.23094789 12.19677863 11.68331209 11.91743862 11.85293185 11.85523513 11.98699226 12.0472613 11.74129456 11.80487121 11.48261351 11.43378078 12.37429821 12.16129283 11.75879827 11.50443904 11.89752657 12.24371212 12.55523195 12.71983559 11.55364116 12.17263214 11.82373819 11.97651457 12.605104 12.48158891 12.25848676 12.27088563 11.89653565 11.79912581 11.4351004 12.3156165 12.58287128 12.13174905 11.95520063 12.26894022 12.28899469 11.76273515 12.1670265 12.15060783 11.75970929 11.90841029 11.84931221 11.72267225 12.12110928 11.71876402 12.21872422 11.87165515 11.72197995 12.08085271 12.06704289 11.61142896 12.20342347 11.83040429 11.89417746 12.17960678 11.94212853 11.74729049 12.37129543 11.80692718 11.60664706 12.296679 11.94310357 11.72118749 11.77114409 11.91568436 12.6672096 11.84339774 12.81772376 11.67239444 11.94270361 12.19301332 11.8827181 12.12819394 12.5254037 11.3959717 11.83406718 11.82504521 11.59809595 12.13282796 11.80783244 12.06061346 12.27923353 12.35779542 12.27164621 11.48999429 12.66486746 11.77565232 12.57685023 11.8266953 12.60358867 12.33741663 11.72861133 12.33074767 12.37743877 12.31895091 12.08513977 12.32783572 11.5668028 12.40381963 12.10782325 12.22429818 12.33060008 11.7748934 12.20221569 11.94489831 11.83022704 11.71419963 12.24991822 11.8035087 12.74124129 11.88389249] r2 score on testing dataset: 0.7647962134922948 MSE on testing dataset: 0.03981209083016479 RMSE on testing dataset: 0.19952967405918548 MAE on testing dataset: 0.13763353158806296
C:\Users\HP\anaconda3\lib\site-packages\sklearn\base.py:413: UserWarning: X has feature names, but KNeighborsRegressor was fitted without feature names warnings.warn(
for i in y_test_pred:
print(np.exp(i))
130461.99189524478 274801.0515804788 108633.47961795505 125340.7244145375 299418.2703952052 95235.55236407349 217030.6991051755 155494.35511651236 95001.59135082894 123805.92053715135 136151.7113431041 127245.8579901885 115888.07391671668 205215.06461661603 182634.49654913446 132361.52443604424 197196.2793204567 132763.54251470132 119128.75193532005 205673.11170915308 150265.99187841732 204209.6009948536 205586.36283271605 134276.22061882238 206976.8388950135 196585.79964629211 205756.45439292878 119152.1475019512 185983.07868405269 209535.20492508865 122988.30287165196 251040.91408239026 142526.57163813585 121738.24297846718 232885.0886371412 139056.81487156634 130017.95201186753 214046.60800475103 234039.31838384652 105180.58934998074 144544.19446886805 211103.1881278937 122805.87956947068 300320.95221265015 129691.70271858636 114505.99915032407 126295.07609424581 125535.98922983759 349446.45392327965 136579.4670152506 128567.37689174459 197326.83191510173 137799.43471647918 258007.78918258174 179857.59931252323 211480.85231197343 223777.388399024 180684.73258600887 144303.38539315012 106198.21161820255 107476.09618231362 144641.7624703967 262391.7861499468 231561.99752093886 274800.97732061933 137690.04330335508 121159.32068541445 272098.5677417299 109604.2056604745 152548.15390023513 110539.77763418734 135698.58157303973 126804.23265144248 103267.07828436732 381643.61349598237 211246.02865923283 257938.897283289 278625.7029358188 136075.64651755829 120702.95688027846 119358.18743412005 100475.58370565111 125455.8053335609 110415.9908751301 169324.70107076064 123059.82552623062 220398.5660066339 217964.23104661138 179168.9819043446 195811.57727784995 115853.50938901697 160212.44841246813 129465.78446720961 224352.75507362263 109716.73835326341 202743.25394936942 128749.80028816656 182880.72407752532 213233.2405497615 242249.6082928465 152081.9416174114 215017.79209747983 186361.91978869893 115218.04628102922 179395.22114055988 161477.24322314156 137717.68804934694 226076.1034044187 157251.86591651334 214005.1911336681 79378.62632563422 107623.09038835272 126683.39234761178 121707.10475788872 194244.43862554594 132054.36149658385 116362.79179162055 124257.9039651398 109141.98930211247 220138.25402701556 158531.80097777274 178895.8393991538 186096.6938920923 157694.65417637356 177152.57046551644 129437.27415978814 219054.56819909456 120606.41952614706 181591.61405442833 181619.4013718838 203764.64896647434 297668.120504082 195766.72952575792 145235.9394791658 115483.48602548124 347193.42652934184 333418.7492128595 133125.21047165053 225886.70142897512 322482.6620697927 265854.3151232488 126215.45052257663 212812.51927414557 135689.63213974098 131256.3877472481 136871.33082715448 180415.0207660504 201631.01766893922 134422.9740636416 88345.58223881912 122940.03045093498 155846.58607779891 226197.37002928718 140846.5786403863 114494.50102577545 127022.3252232977 139157.44387129176 138195.4883233726 97063.22049701968 141845.21182912868 200763.9259262754 135533.46001452138 281084.6086051189 134342.33111195065 124439.46686740631 110986.98363324218 260411.9669180649 291309.5545130819 335700.4745342391 144972.23066955505 294427.9942913468 98116.3032606719 145643.51118965997 130410.85729574216 263364.4959271475 119830.26698799006 121842.07086746096 218300.71939481757 117693.24064703975 172702.83190335124 177106.5157265364 105687.43411275886 125417.71725396205 130318.98866843166 251283.35904458628 129303.74776925355 275317.90950116474 228623.3296618944 205312.37942109688 102439.97296041514 110582.22789222353 112152.41261624712 136536.96647980256 177572.13171141996 216806.94505066762 132004.5293300997 206979.6854578481 114261.42955492201 185111.80024489775 142670.92509891343 190904.4010536921 192441.64868650108 123646.35892854932 261276.19844021893 204200.25640492808 137938.94362031514 223389.32649048694 127983.70525640494 134674.14839491976 135713.89418665358 233272.25838882395 153095.24259316534 103746.08765529201 156026.95608669132 169116.09719680026 224561.24446566802 198587.5269182018 155725.56080273478 141747.78326302092 119683.39321199579 126445.80093490424 223035.8543683148 194652.97557941853 112882.19207052993 203913.11643875553 136753.8158851982 122199.71103636367 109697.55172717189 170958.18052343288 124875.65180177466 111366.25904670682 192816.31812622768 135262.25112532606 130858.79093965773 230435.35990494696 127615.05984295016 210967.66783551182 168366.40853352746 237665.36428984176 155224.968420353 114924.98449311411 227512.70074525033 206845.45233466444 283550.2659809343 186419.61559494067 113033.46415033565 168480.2733574134 184697.23895552524 144852.48348522492 112228.9810506952 206665.44151201707 201283.38449299868 131328.49650287713 98226.51818737447 141558.5864417929 148871.6198104518 122877.74030076215 105860.56815586484 199933.54797463331 233688.60030499016 239455.068133756 163491.03625845723 128233.07030258469 230352.76948747836 345974.2610278894 230747.2388360742 172494.66434282335 179299.84935929015 128029.12787383953 189182.25239021433 351186.9385296801 215507.79214664715 223360.5039980246 114466.35551769238 113279.96279454867 130247.56659000626 168557.0862513664 264942.57452047366 163579.25847714816 132341.20565059138 223424.1336826459 103352.3677909761 214032.071522958 122944.22008899302 271722.70441027096 159886.5852346351 206182.5718317116 111433.77853765422 276203.7565940367 212629.0436062781 130072.98048565128 120300.8048806448 130376.33816193254 189303.5028715021 87634.33268551224 138378.44089634306 136562.29434489246 130618.88678818711 194938.77331604497 127743.24437373357 170752.45214713106 231926.63061789982 121198.34248297183 148717.64784231302 161949.67126547347 157999.22952859948 135176.84519203633 205550.2675354458 150555.97380002652 122809.98943391746 152122.5922496574 160471.51371226305 112372.34686518689 141031.67803653015 126010.83921805756 185280.2098027953 207138.2083768456 180649.1520336859 231020.98975480234 104535.39739273408 231103.67485743738 134499.60782115793 137679.69356064213 92739.31885319416 160185.28976183137 152086.7452112377 132656.8078258993 205037.44216388182 198149.8078797412 118576.32099785634 149857.27476164047 140495.65638847032 140819.62976536236 160651.42942553255 170631.4598810088 125654.90239649732 133903.036870187 97014.28488634621 92390.62397729441 236640.6930175784 191241.6006777956 127873.69089557335 99154.94816285306 146902.82098645924 207671.36269391578 283575.01052865025 334313.8810408764 104155.59475982173 193422.48850992543 136453.36550216415 158976.9609867309 298076.07060310926 263442.1048270633 210762.40968061105 213391.89326821396 146757.32452395838 133135.9160530679 92512.62514575478 223153.80003744556 291522.15346451435 185674.24659355154 155624.3901339035 212977.16182036992 217291.42157813435 128378.10688259252 192341.26664451207 189209.06132996464 127990.23958311348 148510.4026158786 139988.0313758759 123336.5716407154 183709.18747724392 122855.48489422111 202546.3887621474 143150.9790330081 123251.21524159914 176460.5667595379 174040.42719721366 110351.8266604316 199470.8662699163 137366.01514350105 146411.65046779072 194776.25786034114 153603.2919111171 126410.58361609081 235931.1800288782 134178.6205924088 109825.39438566526 218967.58819307544 153753.13457750742 123153.58184525899 129462.1822081244 149594.61700618782 317175.20527530345 139162.51993151344 368694.5346413813 117288.78774893099 153691.65160429888 197405.11640324024 144743.44414797187 185015.32562850878 275241.3684412604 88962.63267724651 137870.09493628665 136631.82962648832 108890.26954579467 185874.6799598967 134300.1414169616 172925.03521340204 215180.72276599912 232767.50952158848 213554.25703331942 97732.97466781779 316433.2062184272 130047.1448355144 289772.1589715875 136857.46971774046 297624.72904579033 228071.99663421605 124071.25619462677 226556.05344084615 237385.046334967 223899.12814344768 177218.68734667022 225897.2938169763 105535.51434417034 243730.8039599567 181284.56364548553 203678.52671270288 226522.61818807686 129948.4876948296 199230.09553663337 154029.32856344254 137341.67034977317 122296.00144878101 208964.1988070504 133720.71709774015 341547.242067101 144913.52898096296
model = DecisionTreeRegressor()
model.fit(X_train.values,y_train.values)
DecisionTreeRegressor()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
DecisionTreeRegressor()
y_test_pred= model.predict(X_test)
print( 'r2 score on testing dataset:', r2_score(y_test, y_test_pred))
print( 'MSE on testing dataset:', mean_squared_error(y_test, y_test_pred))
print( 'RMSE on testing dataset:', (mean_squared_error(y_test, y_test_pred)**.5))
print( 'MAE on testing dataset:', mean_absolute_error(y_test, y_test_pred))
r2_test.append(r2_score(y_test, y_test_pred))
MAE_test.append(mean_absolute_error(y_test, y_test_pred))
MSE_test.append(mean_squared_error(y_test, y_test_pred))
RMSE_test.append(mean_squared_error(y_test, y_test_pred)**.5)
r2 score on testing dataset: 0.7752183153170734 MSE on testing dataset: 0.03804797950079332 RMSE on testing dataset: 0.19505891289759952 MAE on testing dataset: 0.14360439892102086
C:\Users\HP\anaconda3\lib\site-packages\sklearn\base.py:413: UserWarning: X has feature names, but DecisionTreeRegressor was fitted without feature names warnings.warn(
for i in y_test_pred:
print(np.exp(i))
149899.99999999994 275000.00000000006 159999.9999999999 144999.99999999994 378499.99999999977 79000.00000000006 201800.00000000003 148499.99999999997 80999.99999999994 108000.0 189950.00000000012 108000.0 86999.99999999997 159894.99999999994 192999.99999999997 131999.99999999994 202500.00000000003 120499.99999999994 108000.0 204000.00000000006 179999.99999999997 173999.99999999997 148499.99999999997 117000.0 188499.99999999997 161999.99999999988 250579.99999999983 86999.99999999997 186499.99999999985 176000.00000000003 117000.0 233000.00000000006 177000.00000000006 104899.99999999994 275000.00000000006 135999.99999999988 159434.00000000015 194999.99999999994 319000.0000000001 165000.00000000006 134899.9999999999 233000.00000000006 114500.0000000001 317999.99999999994 132499.99999999994 138999.99999999994 114500.0000000001 128500.00000000012 415297.9999999998 138999.99999999994 109500.00000000007 191999.99999999994 100000.00000000001 234999.99999999994 139999.9999999999 171000.00000000003 225000.00000000015 132249.99999999994 165000.00000000006 90349.99999999997 60000.00000000002 156999.9999999999 248899.99999999997 236499.99999999983 275000.00000000006 234999.99999999994 114500.0000000001 305999.9999999999 146999.9999999999 142500.0 128000.00000000004 114500.0000000001 109999.99999999991 92899.99999999993 412499.99999999977 144999.99999999994 336999.9999999999 327999.99999999977 132499.99999999994 136500.0000000001 94499.99999999999 91500.00000000001 129899.99999999996 117000.0 163990.00000000003 107000.00000000003 252000.00000000017 197000.00000000012 139999.9999999999 200141.00000000006 142953.00000000006 106000.00000000004 108000.0 293999.9999999999 117999.99999999991 144999.99999999994 122000.0000000001 142999.9999999999 221499.99999999994 191999.99999999994 172999.99999999985 223500.0 327999.99999999977 171899.99999999988 217999.9999999999 142999.9999999999 143749.99999999997 319899.99999999977 137999.99999999988 197499.99999999997 54999.99999999995 147999.9999999999 120499.99999999994 159434.00000000015 237000.00000000003 88000.00000000001 79000.00000000006 111250.00000000004 167999.99999999994 312500.00000000006 165400.00000000006 142999.9999999999 175000.00000000003 240000.00000000015 180999.99999999985 123000.00000000003 268000.0000000001 127499.99999999991 124499.99999999993 176499.9999999999 196000.00000000006 319000.0000000001 225000.00000000015 126999.99999999996 60000.00000000002 378499.99999999977 582933.0 117499.99999999996 213000.00000000003 625000.0000000002 289999.9999999999 144999.99999999994 183200.00000000003 175000.00000000003 129899.99999999996 120000.00000000006 222500.00000000012 180499.99999999988 136500.0000000001 61000.000000000044 104899.99999999994 179900.0 210000.0000000001 131999.99999999994 100000.00000000001 137000.00000000012 109999.99999999991 155000.0 88000.00000000001 128500.00000000012 170000.0 146999.9999999999 372401.9999999998 119000.0000000001 115000.00000000009 124999.99999999991 142999.9999999999 295493.00000000023 345000.00000000006 222500.00000000012 326000.00000000023 100000.00000000001 159434.00000000015 168499.9999999999 301500.00000000023 159999.9999999999 135000.00000000012 165400.00000000006 109999.99999999991 168499.9999999999 217999.9999999999 109500.00000000007 142953.00000000006 171899.99999999988 277499.9999999999 139999.9999999999 305999.9999999999 173999.99999999997 202500.00000000003 83499.99999999993 106000.00000000004 109900.00000000003 120000.00000000006 124499.99999999993 180999.99999999985 177499.99999999997 187500.00000000006 106250.00000000009 265900.0000000002 116000.00000000006 302000.00000000023 260000.00000000015 165000.00000000006 312500.00000000006 196000.00000000006 128000.00000000004 226999.9999999998 132499.99999999994 124000.0000000001 120000.00000000006 214000.0000000001 165000.00000000006 76499.99999999996 131500.0000000001 260000.00000000015 237000.00000000003 159894.99999999994 132499.99999999994 112500.00000000006 144999.99999999994 121500.00000000004 202500.00000000003 170000.0 88000.00000000001 226999.9999999998 190000.00000000012 102000.00000000003 96999.99999999997 210000.0000000001 100000.00000000001 109999.99999999991 177999.99999999994 124000.0000000001 141000.0 236499.99999999983 137000.00000000012 198899.99999999997 131500.0000000001 274299.99999999977 119000.0000000001 75999.99999999999 266500.00000000006 200000.00000000006 466499.9999999999 187500.00000000006 109500.00000000007 147999.9999999999 143749.99999999997 134000.00000000006 88000.00000000001 228949.99999999997 175899.99999999988 115000.00000000009 88000.00000000001 138799.99999999997 139999.9999999999 117000.0 117999.99999999991 155000.0 275000.00000000006 372499.99999999994 158999.99999999997 139999.9999999999 260000.00000000015 248327.99999999988 180999.99999999985 109999.99999999991 139999.9999999999 197499.99999999997 178739.9999999999 314999.99999999994 213500.00000000017 237000.00000000003 100000.00000000001 109999.99999999991 142599.99999999994 130000.00000000006 265999.99999999994 178999.99999999994 139999.9999999999 200000.00000000006 91500.00000000001 186499.99999999985 86999.99999999997 312500.00000000006 175000.00000000003 237000.00000000003 155000.0 200999.99999999994 164990.00000000012 106250.00000000009 111250.00000000004 178999.99999999994 167999.99999999994 121000.0 159434.00000000015 137449.99999999988 124999.99999999991 207499.99999999985 100000.00000000001 182900.00000000012 232000.00000000015 109999.99999999991 167499.9999999999 159894.99999999994 226000.00000000003 175499.99999999988 216499.99999999988 210000.0000000001 137999.99999999988 147999.9999999999 215000.00000000006 144999.99999999994 139999.9999999999 140200.00000000006 173900.00000000012 196000.00000000006 171899.99999999988 289000.0 92899.99999999993 279500.0000000002 142999.9999999999 144999.99999999994 109500.00000000007 187000.00000000017 175000.00000000003 134800.00000000006 202500.00000000003 165000.00000000006 109999.99999999991 135959.99999999988 178999.99999999994 120499.99999999994 166999.99999999985 171899.99999999988 132499.99999999994 144000.00000000012 106250.00000000009 121000.0 250579.99999999983 187000.00000000017 137000.00000000012 159434.00000000015 210000.0000000001 199900.0 378499.99999999977 384999.9999999997 108000.0 187500.00000000006 118500.0 314999.99999999994 412499.99999999977 234999.99999999994 176499.9999999999 244999.99999999983 139999.9999999999 126000.00000000007 99900.0 208500.00000000012 439999.9999999997 211000.00000000017 109999.99999999991 249999.99999999983 210000.0000000001 135999.99999999988 180999.99999999985 149299.9999999999 132999.99999999997 147999.9999999999 124999.99999999991 139999.9999999999 175000.00000000003 144000.00000000012 184099.99999999997 182900.00000000012 162900.0000000001 185000.00000000006 193499.99999999997 89499.99999999997 193499.99999999997 151999.99999999997 159999.9999999999 177999.99999999994 121500.00000000004 139999.9999999999 184099.99999999997 143500.00000000012 112000.00000000003 255899.99999999977 210000.0000000001 109500.00000000007 256000.00000000012 143250.00000000012 474999.99999999994 104899.99999999994 426000.00000000006 112500.00000000006 139400.00000000012 109999.99999999991 105000.00000000004 148499.99999999997 372401.9999999998 138887.00000000012 131500.0000000001 131999.99999999994 100000.00000000001 200000.00000000006 112000.00000000003 206900.00000000003 250579.99999999983 214900.00000000006 187500.00000000006 88000.00000000001 305999.9999999999 156999.9999999999 339749.99999999977 106500.0 426000.00000000006 269999.99999999977 136500.0000000001 266500.00000000006 277999.9999999999 250579.99999999983 165150.0000000001 214000.0000000001 126999.99999999996 222000.00000000012 179540.00000000003 161999.99999999988 274724.99999999994 106500.0 147999.9999999999 217999.9999999999 139400.00000000012 141000.0 176485.0000000001 110500.00000000003 412499.99999999977 151999.99999999997
reg = GradientBoostingRegressor(random_state=0)
reg.fit(X_train, y_train)
GradientBoostingRegressor(random_state=0)
GradientBoostingRegressor(random_state=0)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
GradientBoostingRegressor(random_state=0)
y_test_pred= reg.predict(X_test)
print( 'r2 score on testing dataset:', r2_score(y_test, y_test_pred))
print( 'MSE on testing dataset:', mean_squared_error(y_test, y_test_pred))
print( 'RMSE on testing dataset:', (mean_squared_error(y_test, y_test_pred)**.5))
print( 'MAE on testing dataset:', mean_absolute_error(y_test, y_test_pred))
r2_test.append(r2_score(y_test, y_test_pred))
MAE_test.append(mean_absolute_error(y_test, y_test_pred))
MSE_test.append(mean_squared_error(y_test, y_test_pred))
RMSE_test.append(mean_squared_error(y_test, y_test_pred)**.5)
r2 score on testing dataset: 0.8979173082348175 MSE on testing dataset: 0.017279166535059256 RMSE on testing dataset: 0.1314502435717 MAE on testing dataset: 0.09077315700353661
for i in y_test_pred:
print(np.exp(i))
140708.13233772956 332470.0234738757 119095.99883857284 150886.60087869386 320943.2143227177 79725.6818471504 230081.1632802578 146062.05665816224 76501.12947635211 134897.70921464183 158914.28916320996 123204.28607416539 102345.0185426666 199880.92019352462 171270.3958673714 136908.0301079267 195901.87341200822 128390.70568760534 112236.79941110632 219237.94547420027 161396.80663702288 228896.42863140503 172489.42364707068 122701.07742739658 198606.94345181173 168597.94718265053 196481.91877250536 110596.48329832595 170013.97031362716 182858.46749268772 124591.77217988427 259175.17626281272 206421.74030454818 115862.11811705833 261465.36561882353 146906.72082998467 120506.11448039726 209872.50683533776 329088.425615985 107491.86153697174 130732.16148707645 246504.4308834956 121857.94410196415 345694.32843441004 127534.62697882424 112537.35453826727 117361.04029053677 130881.70602387986 422607.55082352436 135128.81723145585 122253.59267717565 191919.8896294768 108962.46966812473 300787.0948473435 143702.46370124185 249793.6118178364 194847.68463217583 149000.7712109692 145508.4068407708 105125.99490875182 65004.451194742884 147451.45918855668 300819.18274974683 293896.17549450934 277034.93536500016 226050.5201701328 111753.19596918792 335069.8749086868 121268.10150742829 161929.12666269462 125837.09279871883 128973.68766671204 116006.06619786122 91278.46216265207 352863.7502082334 174286.7886177079 321892.1957774616 317640.11748855247 137686.1398596438 117508.52336561425 108335.45533826681 86431.10595164617 119779.70205823325 98929.33275220628 153528.85550105298 128658.25126281113 271431.1260561865 202901.63305486392 143405.22092178406 179000.8069714832 144216.6379957549 142480.31942719704 128360.08955387819 264362.5892771139 100118.7760265502 166269.25308305625 189720.00134031306 170002.90669627857 209990.95983680332 235622.59900131327 168682.6106936469 204695.80540238885 279855.25300946686 147758.16000086543 174521.34169797375 138365.19664267977 152089.4529560399 254659.35884069838 141042.09115727345 174361.0528732442 51825.29199148055 120518.82171540664 136257.71769607914 135919.2922337874 203430.38273808802 115147.785064821 109384.88942160773 111051.95978086202 129319.74600061082 277128.16340834554 153761.14549323192 143405.22092178406 172111.48286808448 195214.66249442886 178161.44737523727 127132.60205577739 238238.34946804564 112080.17577715068 143629.64609867203 184070.96460300498 192050.04666891103 354790.7618644437 196151.80526393314 109190.33611986363 63616.098689059654 350521.3822055389 395617.3540127147 128605.0973725017 235772.4189549346 562621.8612518581 355324.3695403825 130601.64869254085 165989.26173629382 163230.07714578067 128636.73177872307 130791.74379508613 248637.11563840337 193954.79005285408 117929.95143841609 59925.57229175122 112667.12886232787 142902.3908122345 206515.46094542905 139790.2660741526 87971.54616753539 116262.62381724516 127170.76832255616 145360.40862857888 91379.40561395731 130844.3472954855 203161.55139807236 155321.38527663113 320648.6571257984 157557.77354291372 116294.64731482785 107034.69925689072 214745.26611168394 339028.29175430915 417814.97576625354 235864.37627277878 376200.46494836407 93235.99571551288 120097.96713161303 146210.71657419862 333997.184883162 143405.52489842652 136991.49280001686 218552.38131217964 118623.00750239432 172406.83800885934 171078.51342266236 95989.07033573999 129025.25122539226 140850.9529759802 269914.5188533308 142945.71344951543 304944.6285526498 226059.63596759908 184532.8811571981 82424.5002209505 115857.7354725355 108616.11193403054 127398.38209185503 158070.63603148723 167106.47916217687 161644.71375908764 215620.64513848952 91387.98451594393 215634.3183194984 126009.61667246973 215122.4025582446 188449.91225918848 125142.92619383315 349725.6490411109 191219.6551914497 124264.69883307547 252872.41076035425 143380.79114405895 151434.6856258815 115636.0517849128 256746.66471663222 140999.02035959857 112346.23209157497 163833.0852886614 209409.7824897041 279205.2580429309 184108.4608982958 142050.03718622166 117913.73263379264 132369.04003471043 135351.79340198037 206383.11001336342 208970.34981666695 96984.12700846289 237124.4189708159 143405.04646156172 104963.65988657955 104105.16317598532 173467.39146841594 106107.24184943057 107567.67546720884 182655.3721352089 124610.09150395764 124834.12293262043 237423.6227315565 137022.35596797153 197591.44740617712 149678.66789088256 243796.2010056532 122484.31852836718 118265.82566722367 262453.951014605 201447.25578613929 385375.1093196659 181748.7378778706 118611.39549052047 152505.82190161519 165328.89801602898 142001.50536215125 98123.2528840535 167703.05812590383 173892.9638313459 139481.101463981 87174.17155177308 140913.34302589906 148079.66975007963 112270.82494730805 109344.61051379555 175337.3235429706 266776.898453688 281865.14775100065 162578.2126125384 127860.55881465868 234551.55182034068 285971.77299701096 188559.70283647132 175231.72284587656 141190.83830731447 126273.54526346842 170486.76934300005 396169.5176241579 200024.06699696777 227629.52190170594 95678.26308747882 105470.34317755635 133659.29709506256 148883.13626009805 247408.7594202505 211870.24308682763 149657.34397478824 201641.3960427369 92019.31636571368 192313.32420349366 111677.96439843981 319609.97821898805 166531.02027760437 209361.73021605797 119059.26077269773 240196.46460110226 183890.48009770978 124043.41125986128 119463.84112589074 139382.12869289643 176739.0247251848 101051.04619589474 145430.35903593642 134765.04051859764 135228.16851483582 173728.15780271616 105170.61654883533 179968.93183465648 238017.812113703 117732.78003426283 147183.57281001259 179976.61542224622 213935.0888402398 156113.23655039544 194771.1525369557 206927.41667821773 134524.0981323788 159276.80787480905 192144.90596606865 90374.67820648848 153270.8822707766 130742.39846502023 175924.24400522045 190730.0111846883 160848.28464473723 305544.2881688981 91744.09582436699 227148.9857232289 138639.40884242544 131960.55752752518 93185.09881116876 182904.30715092993 163741.20559749904 132285.56643925255 186536.87239842344 173597.9493108586 101779.13525528264 152915.59089992166 148928.9760580744 132915.8717476992 211688.66655730305 155932.83761048244 132243.66077580347 119201.89068753034 98494.66505949634 81344.83692743372 202838.79220498592 178955.48623285137 129722.4459387574 138168.53936010879 184410.65394855963 214664.359285564 340197.49966478185 331018.5889092181 122762.99961767161 204852.49124845662 122080.46173703251 316728.2270728153 372608.5067795688 251121.35088899438 160761.33801981685 271580.78228310763 141447.65172686044 126729.27037468662 88598.9663430247 201667.77730439007 361182.7814312383 176272.27736552354 129182.2340299067 259689.5442925935 217050.8409388138 129662.63331619467 194237.28088779873 185591.5731356239 104084.76621660296 130253.07194049393 149939.79343834112 119988.38861988165 171973.28533331348 122665.7899009083 186933.53074910527 152942.99834818122 127763.60611729044 201916.77743885733 195562.8828200801 97077.84320042226 208681.48743070965 149490.43753523126 189447.00695711595 187531.66144121703 163033.19752031128 134784.8757671696 230037.76893879558 140186.2900479613 109190.44657384066 290776.51632234757 179059.4336465179 117996.27106811272 153452.3243560171 137712.57443169213 327945.0462323989 152388.3227316876 423889.4134957632 126572.37908407439 162226.3728396428 164433.9827269322 134821.3895453943 160378.49789962504 413214.0387677283 118802.43215211836 155743.69773125672 138591.90289050806 110854.87435893212 205134.91904661816 139643.07410787622 235929.30417860288 209886.06129323205 217081.2055854618 210822.75918490544 74851.01646677255 286823.9379829387 143317.52206910084 352911.1411196107 124797.97885567194 363928.0806078404 284541.3665469354 127807.96918868122 222606.6922277184 254796.67187934744 209886.06129323205 178728.80163786418 254373.04435403374 123389.92618059838 210088.59689398104 167587.71133464418 188239.64769065566 225824.71736088567 123360.63805927477 148035.299553689 171430.59944024181 138956.76803476617 116316.7303531084 201455.78446404822 135432.7588850054 428509.35492316476 180100.9034882829
from sklearn.ensemble import RandomForestRegressor
regr = RandomForestRegressor(max_depth=2, random_state=0)
regr.fit(X_train, y_train)
RandomForestRegressor(max_depth=2, random_state=0)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
RandomForestRegressor(max_depth=2, random_state=0)
y_test_pred= regr.predict(X_test)
print( 'r2 score on testing dataset:', r2_score(y_test, y_test_pred))
print( 'MSE on testing dataset:', mean_squared_error(y_test, y_test_pred))
print( 'RMSE on testing dataset:', (mean_squared_error(y_test, y_test_pred)**.5))
print( 'MAE on testing dataset:', mean_absolute_error(y_test, y_test_pred))
r2_test.append(r2_score(y_test, y_test_pred))
MAE_test.append(mean_absolute_error(y_test, y_test_pred))
MSE_test.append(mean_squared_error(y_test, y_test_pred))
RMSE_test.append(mean_squared_error(y_test, y_test_pred)**.5)
r2 score on testing dataset: 0.682602215775255 MSE on testing dataset: 0.05372477034690355 RMSE on testing dataset: 0.23178604433162828 MAE on testing dataset: 0.16892784466381583
for i in y_test_pred:
print(np.exp(i))
128347.2157313713 275025.7840522569 135182.39927129564 152329.46419571684 287878.4878786661 109751.04496100584 204620.12719874937 151772.18334219104 109751.04496100584 137070.7814729995 203925.31900262166 125279.43735329676 119351.24824868738 203925.31900262166 152784.3612357372 125279.43735329676 203925.31900262166 127609.70757527355 128380.65329795305 205594.69650408288 151032.14433157534 270849.11956944776 151772.18334219104 127287.29442234572 207777.1269690089 140524.93062498592 203925.31900262166 119351.24824868738 152784.3612357372 203925.31900262166 141726.5717557559 219441.5161864101 138470.1295791796 110340.03542474248 284016.29682665004 131159.11841908644 139213.2440147963 204620.12719874937 288396.0074987039 127287.29442234572 140106.53456354802 205388.61981027442 125279.43735329676 292473.92074627965 135915.38792178867 140409.0431449171 125279.43735329676 127287.29442234572 296451.12266136473 141444.41859544234 124906.43291248578 152784.3612357372 132729.5764106234 281197.8992260162 137492.2260267253 210208.64261211827 203925.31900262166 138443.4929953244 140049.66120389526 128033.01978465356 109530.60090317688 131544.1242001907 286054.304066583 267255.121780921 290390.17664769845 152784.3612357372 125333.8120358036 286054.304066583 124610.70099102044 151772.18334219104 151032.14433157534 130094.9059815607 112108.45827854153 119236.09601722367 296451.12266136473 143370.8289825761 288396.0074987039 221237.91268979543 129252.02794503437 127287.29442234572 126732.88124662083 128524.88096365561 135510.71621875066 125279.43735329676 149920.43220039873 122612.25465810028 284983.9885867225 205594.69650408288 137492.2260267253 203925.31900262166 151032.14433157534 151032.14433157534 125279.43735329676 205388.61981027442 121424.62278603952 144206.547221187 207777.1269690089 203925.31900262166 207777.1269690089 205388.61981027442 152784.3612357372 203925.31900262166 211717.03047692258 203925.31900262166 149597.53034988642 151772.18334219104 137962.66862645478 274018.73636395537 135915.38792178867 151032.14433157534 108945.93116683864 125037.0682397183 125708.09274643663 139213.2440147963 203925.31900262166 125279.43735329676 110340.03542474248 119707.66340341592 152784.3612357372 286341.3166833783 203925.31900262166 137492.2260267253 152784.3612357372 151894.47225765017 149920.43220039873 125279.43735329676 205388.61981027442 127287.29442234572 129654.91195076672 203925.31900262166 203925.31900262166 293764.88265408616 203925.31900262166 139659.54558388767 111286.0509271136 294339.0428021172 294339.0428021172 127287.29442234572 220653.01351930402 296451.12266136473 286054.304066583 125279.43735329676 152784.3612357372 152329.46419571684 136636.93878154526 125279.43735329676 205388.61981027442 203925.31900262166 128033.01978465356 108945.93116683864 112438.0660181824 144661.81363184212 152784.3612357372 151032.14433157534 110925.81124191586 138470.1295791796 124825.87149602857 145436.71772277754 109751.04496100584 127609.70757527355 265828.072201697 139243.6139828479 287633.5586783002 141444.41859544234 130069.41452116633 137864.81366363764 204620.12719874937 286054.304066583 294044.0137092918 205388.61981027442 295341.905910923 109751.04496100584 138057.85144045323 152784.3612357372 273744.0752166026 133021.767242015 140409.0431449171 203925.31900262166 133820.91150629197 152784.3612357372 141726.5717557559 135379.97304187753 135915.38792178867 203925.31900262166 267776.87399090023 203925.31900262166 290039.67189832084 215589.56677101663 203925.31900262166 111745.55641095081 143772.35559369926 128908.6910704398 130246.91903990819 131159.11841908644 143370.8289825761 139213.2440147963 268004.1992523287 114879.43884361023 265828.072201697 131006.13712169636 203925.31900262166 203925.31900262166 134285.4083245264 288396.0074987039 203925.31900262166 127287.29442234572 266733.793591419 138443.4929953244 140828.3425789166 125279.43735329676 219441.5161864101 143370.8289825761 113468.71687425637 151772.18334219104 203925.31900262166 273066.35001788463 213839.0334234306 130414.50823748426 132521.5642698341 151032.14433157534 135915.38792178867 265828.072201697 151032.14433157534 127229.7650354461 278751.1540717218 130798.2624889135 121571.25071377953 110340.03542474248 152784.3612357372 114240.11406736201 112108.45827854153 152784.3612357372 126732.88124662083 114077.65861321762 266733.793591419 140403.27946088486 203925.31900262166 137492.2260267253 207069.97621390488 126732.88124662083 137492.2260267253 209997.94115524186 203925.31900262166 282258.54302498116 152784.3612357372 131108.5762753764 140858.32951887453 140049.66120389526 137646.68997672608 124906.43291248578 150152.4611003175 203925.31900262166 139213.2440147963 124906.43291248578 130094.9059815607 139243.6139828479 131025.79046915511 130635.87161881877 152784.3612357372 269927.3089629734 291379.5852988488 140524.93062498592 127287.29442234572 206522.53361761256 224591.32980639866 152784.3612357372 144206.547221187 137492.2260267253 119351.24824868738 203925.31900262166 296451.12266136473 265828.072201697 208485.05892906178 129654.91195076672 123762.6026360569 135915.38792178867 203925.31900262166 274183.86699495575 141330.54292708702 138798.75334231017 203925.31900262166 124610.70099102044 203925.31900262166 125279.43735329676 292767.374486162 152784.3612357372 204620.12719874937 121934.29539717831 205594.69650408288 203925.31900262166 123445.80051355826 119707.66340341592 131823.90067206955 151894.47225765017 124239.68763221065 138798.75334231017 141023.28486928047 135915.38792178867 152784.3612357372 112773.83653826754 151333.10341388546 265828.072201697 126732.88124662083 137646.68997672608 203925.31900262166 204620.12719874937 203925.31900262166 152784.3612357372 152329.46419571684 135915.38792178867 151333.10341388546 152784.3612357372 124360.41008413104 151032.14433157534 138798.75334231017 152784.3612357372 203925.31900262166 203925.31900262166 210924.85915893115 119236.09601722367 203925.31900262166 129523.11308068194 130246.91903990819 123696.57945072567 152784.3612357372 133021.767242015 135915.38792178867 203925.31900262166 152329.46419571684 110340.03542474248 140519.34244846206 137498.03686223167 125279.43735329676 219661.69285531077 203925.31900262166 137646.68997672608 140898.58648121016 121149.80024093195 127459.18110555364 203925.31900262166 152784.3612357372 135915.38792178867 138470.1295791796 152784.3612357372 214567.61932831627 286513.8732133899 294339.0428021172 135915.38792178867 152784.3612357372 112108.45827854153 274257.0811010922 294044.0137092918 269213.68688443396 143370.8289825761 289023.6751651717 128363.91697536428 126891.76744782446 124065.97094139936 203925.31900262166 294868.17657211755 152784.3612357372 129889.61421658132 267735.5667426005 204620.12719874937 129654.91195076672 203925.31900262166 143370.8289825761 131757.99374699633 137890.89460908674 141695.8071354518 128042.76104590362 152784.3612357372 143344.2907154136 265828.072201697 144206.547221187 138031.2941638191 151442.2247549178 152784.3612357372 126732.88124662083 152784.3612357372 139243.6139828479 133021.767242015 152784.3612357372 138443.4929953244 138798.75334231017 266733.793591419 133507.18592700938 149496.07640032453 267735.5667426005 152784.3612357372 129142.60914843531 150152.4611003175 137492.2260267253 291949.0834101169 139213.2440147963 289944.2089273275 136597.66458026972 203925.31900262166 140524.93062498592 146818.25946120426 151772.18334219104 289697.52219582925 137454.33778016848 139243.6139828479 127609.70757527355 109751.04496100584 203925.31900262166 151032.14433157534 152784.3612357372 203925.31900262166 204620.12719874937 203925.31900262166 109424.27443889153 292767.374486162 132729.5764106234 294868.17657211755 125279.43735329676 288714.5742249639 286341.3166833783 127722.81988753776 205388.61981027442 265828.072201697 203925.31900262166 152784.3612357372 219441.5161864101 137864.81366363764 203925.31900262166 203925.31900262166 203925.31900262166 205388.61981027442 127287.29442234572 137646.68997672608 151032.14433157534 128908.6910704398 112773.83653826754 203925.31900262166 140524.93062498592 294044.0137092918 204845.6223109089
from sklearn.ensemble import AdaBoostRegressor
regr = AdaBoostRegressor(random_state=0, n_estimators=100)
regr.fit(X_train, y_train)
AdaBoostRegressor(n_estimators=100, random_state=0)
AdaBoostRegressor(n_estimators=100, random_state=0)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
AdaBoostRegressor(n_estimators=100, random_state=0)
y_test_pred= regr.predict(X_test)
print( 'r2 score on testing dataset:', r2_score(y_test, y_test_pred))
print( 'MSE on testing dataset:', mean_squared_error(y_test, y_test_pred))
print( 'RMSE on testing dataset:', (mean_squared_error(y_test, y_test_pred)**.5))
print( 'MAE on testing dataset:', mean_absolute_error(y_test, y_test_pred))
r2_test.append(r2_score(y_test, y_test_pred))
MAE_test.append(mean_absolute_error(y_test, y_test_pred))
MSE_test.append(mean_squared_error(y_test, y_test_pred))
RMSE_test.append(mean_squared_error(y_test, y_test_pred)**.5)
r2 score on testing dataset: 0.8354327501263884 MSE on testing dataset: 0.027855700781517896 RMSE on testing dataset: 0.16690027196358279 MAE on testing dataset: 0.1262328706994991
for i in y_test_pred:
print(np.exp(i))
124284.36361622355 290947.70965465566 99086.36681323925 151653.13218656415 314401.3043291481 81930.2660914172 195532.44874503763 147322.22063230647 81930.2660914172 99406.03514595622 150666.8324646799 111153.07660328 99259.8702585835 209325.32293770497 165329.80029875177 124284.36361622355 198693.06222303765 122446.34998583047 111153.07660328 240291.59081230924 159236.91456840065 209325.32293770497 169506.8372779379 97038.65252027851 216579.95085040512 167521.71061453532 175105.57050521235 97523.48357074827 165329.80029875177 172823.5219479795 112439.99966382052 243644.9295823406 170106.51831754556 92919.2210232873 255758.14652910447 135077.59282033987 123971.00856038106 209325.32293770497 294201.7990538983 99086.36681323925 119929.6065050812 226521.72135095013 109933.84535245837 285594.796203534 126316.96036699307 132157.99825003874 97523.48357074827 109933.84535245837 380282.1263961287 124892.2645603842 99086.36681323925 188964.1225038802 108980.46321215664 282559.36367302603 164118.39825837014 244382.09425868173 207585.164738001 134077.4222159309 128430.16295256124 105592.59424122075 70443.83082785219 123971.00856038106 270925.749974753 277570.5940314579 262934.8734465334 200979.0582041887 95674.84360156948 284842.80329290044 111153.07660328 162916.7011530049 131552.54679791752 121061.24057514605 94180.05668126472 99409.06815181115 366075.521266941 173018.52239338556 287093.0262248117 273097.27860032336 119929.6065050812 99358.9178392296 121061.24057514605 86901.74189775104 106825.31890824775 95386.52712561103 128919.36242028303 124213.97814998108 233769.86015114872 230951.5164360896 162405.70681611993 192421.46626826617 152757.66266902894 128919.36242028303 114317.03920926267 232930.94950929907 126107.22836584826 172678.06295775637 165836.0864200435 190968.57844218568 208785.40125018446 226521.72135095013 194515.01498506655 205396.3264729432 251867.2657937112 125697.17590673546 172278.62423498044 165836.0864200435 140572.60269431368 262747.963378442 145203.09862165636 154901.4320264489 70443.83082785219 121249.21258222745 119929.6065050812 122446.34998583047 200849.93364428054 100832.36921445173 92050.22403085661 105430.83467818535 150666.8324646799 271946.11053860077 151542.24044217975 162405.70681611993 165836.0864200435 175105.57050521235 158813.96716437192 116707.42559917689 226521.72135095013 92831.60153023167 127568.02217690056 168865.29064239148 200849.93364428054 292531.69427190034 195388.30934801276 137401.98458128105 77848.74580841283 315674.24012033833 294201.7990538983 109933.84535245837 239265.61663679604 469437.65651427885 329684.403112633 108980.46321215664 170112.63006447197 151653.13218656415 122446.34998583047 108787.24993796686 215052.50489160302 202482.03989947267 106068.33612645257 75037.17521973555 102681.85865112036 127866.66061848743 221954.1361579948 132198.15256736253 94180.05668126472 119929.6065050812 131552.54679791752 125697.17590673546 82678.96391732409 128430.16295256124 172823.5219479795 137919.71841914052 285446.41799465986 162916.7011530049 105592.59424122075 124213.97814998108 213583.17226530332 266124.95309785753 416046.27261441865 185828.52825949652 329684.403112633 82411.24279154248 107875.70611585805 162916.7011530049 273097.27860032336 131552.54679791752 132157.99825003874 215052.50489160302 99086.36681323925 169506.8372779379 137716.70064123097 99406.03514595622 123692.44312938725 119771.7670920638 254440.94610690753 152757.66266902894 282559.36367302603 245346.7636968172 172678.06295775637 98633.83395003254 123131.14925523692 96737.11412474293 111491.4572021157 127866.66061848743 172304.4624172707 149697.5106507594 197269.73463995315 91012.41645493484 210154.94474571422 97523.48357074827 234401.92478956917 195532.44874503763 109933.84535245837 293636.6947788285 173018.52239338556 121061.24057514605 234721.98604344437 127568.02217690056 144472.91919150713 102959.23298582736 251580.64237286663 135077.59282033987 121249.21258222745 158055.78345898484 155759.76406898812 273006.97357422364 173809.45560292195 126514.10153895596 99406.03514595622 129080.8651733634 124284.36361622355 185441.4124190557 188681.98554453178 89430.77273228427 254121.93087828282 121639.24439306781 95386.52712561103 95304.00875848692 162916.7011530049 99086.36681323925 96842.37730004155 172278.62423498044 117692.72405119152 120268.65123681357 234401.92478956917 125320.41758816135 175105.57050521235 167521.71061453532 240629.07049163827 127866.66061848743 125829.87485318683 234401.92478956917 197269.73463995315 322465.0364380993 170729.63048848807 117900.19550208379 151542.24044217975 167521.71061453532 134005.54738841025 91597.07981996398 155008.7214503306 192421.46626826617 124284.36361622355 80962.14282358914 125828.0906620236 138487.7256856678 116257.93000354586 103044.40513894468 170729.63048848807 259137.010502594 285446.41799465986 151266.87615963927 109933.84535245837 263845.4534862652 263845.4534862652 205343.76490273292 155008.7214503306 162334.0309794941 109933.84535245837 176009.70402501497 361143.42008747184 176987.00074607666 218770.48467252922 103044.40513894468 123684.47370679505 126326.49474216287 176618.59109144183 271946.11053860077 186300.49870015265 141609.48915326735 200979.0582041887 91095.379005887 197269.73463995315 94180.05668126472 282559.36367302603 186285.7305285068 224363.02882902595 119771.7670920638 270925.749974753 205396.3264729432 120268.65123681357 121249.21258222745 119079.68562613051 170729.63048848807 87916.38683949155 154235.40069452283 132198.15256736253 124196.67017973654 170729.63048848807 108980.46321215664 186300.49870015265 239265.61663679604 126326.49474216287 131552.54679791752 197799.72900371754 195214.77672149267 126326.49474216287 200979.0582041887 222442.97778029667 108787.24993796686 140607.7880478697 208600.40374515124 87916.38683949155 134376.1556820032 121061.24057514605 172678.06295775637 172823.5219479795 167967.38266596335 245346.7636968172 102681.85865112036 217501.0660510018 120268.65123681357 119771.7670920638 78437.6863549197 188964.1225038802 172278.62423498044 124284.36361622355 176009.70402501497 174094.3084326118 99259.8702585835 133721.21844313823 126126.76472700648 111491.4572021157 167521.71061453532 167521.71061453532 120268.65123681357 103044.40513894468 108980.46321215664 98801.37855130657 216579.95085040512 170112.63006447197 114317.03920926267 122446.34998583047 177805.95539955006 226148.80859715783 283491.30132695264 301258.222945188 97462.45079075286 200979.0582041887 118776.48035446838 283491.30132695264 371845.57413814095 275523.5318436075 167521.71061453532 234721.98604344437 121249.21258222745 124196.67017973654 87275.11940152623 205396.3264729432 288933.78892889357 174094.3084326118 129792.93387755321 234721.98604344437 223657.81328879076 116707.42559917689 213583.17226530332 154901.4320264489 106825.31890824775 126107.22836584826 144114.90063980443 112439.99966382052 164227.62096980188 114317.03920926267 176618.59109144183 136443.3845112394 121249.21258222745 186714.09351480592 195214.77672149267 108787.24993796686 203459.2294677347 126326.49474216287 171250.29504704167 172278.62423498044 135161.36798463695 124892.2645603842 225594.02041577073 124213.97814998108 120483.17483259633 256285.10661444577 168036.02612799482 105592.59424122075 154235.40069452283 135077.59282033987 301258.222945188 134376.1556820032 387133.61257616227 119771.7670920638 180631.74569015283 165122.56651583847 123684.47370679505 162405.70681611993 378252.65400852304 120268.65123681357 139434.84313476473 128919.36242028303 106068.33612645257 192057.72754738145 138377.996353592 208785.40125018446 180968.46354646797 226148.80859715783 218066.58923296063 66702.65669395783 271946.11053860077 121061.24057514605 283567.96708271484 98896.01792653067 294201.7990538983 290947.70965465566 126107.22836584826 217501.0660510018 246077.9600093942 180968.46354646797 164227.62096980188 244382.09425868173 127632.09593887294 176009.70402501497 175105.57050521235 172678.06295775637 226148.80859715783 111153.07660328 135696.53854008907 170106.51831754556 124196.67017973654 104140.74708382452 205343.76490273292 138377.996353592 423642.2034903086 187246.50894349872
from catboost import CatBoostRegressor
cb_reg_1 = CatBoostRegressor( random_seed=13, verbose=200)
cb_reg_1.fit(X_train, y_train)
Learning rate set to 0.041078 0: learn: 0.3839109 total: 176ms remaining: 2m 55s 200: learn: 0.0917148 total: 3.33s remaining: 13.2s 400: learn: 0.0660797 total: 7.9s remaining: 11.8s 600: learn: 0.0512503 total: 11.8s remaining: 7.81s 800: learn: 0.0394802 total: 15.1s remaining: 3.75s 999: learn: 0.0314580 total: 17.9s remaining: 0us
<catboost.core.CatBoostRegressor at 0x2d673a79060>
y_test_pred= cb_reg_1.predict(X_test)
print( 'r2 score on testing dataset:', r2_score(y_test, y_test_pred))
print( 'MSE on testing dataset:', mean_squared_error(y_test, y_test_pred))
print( 'RMSE on testing dataset:', (mean_squared_error(y_test, y_test_pred)**.5))
print( 'MAE on testing dataset:', mean_absolute_error(y_test, y_test_pred))
r2_test.append(r2_score(y_test, y_test_pred))
MAE_test.append(mean_absolute_error(y_test, y_test_pred))
MSE_test.append(mean_squared_error(y_test, y_test_pred))
RMSE_test.append(mean_squared_error(y_test, y_test_pred)**.5)
r2 score on testing dataset: 0.910935258668458 MSE on testing dataset: 0.015075665338152718 RMSE on testing dataset: 0.12278300101460592 MAE on testing dataset: 0.08067298395188066
for i in y_test_pred:
print(np.exp(i))
145536.5925795407 331208.6618823944 111495.4125997253 151084.82605588835 342387.6057437851 75971.64255242128 229916.72426701296 141405.43422092384 76475.35070315203 134464.92076933675 149608.86159066486 119489.37184898795 106973.59343264543 200288.25085418165 175957.0778921774 134535.76626566163 195808.25526384867 136093.2783709987 114810.76316862379 214071.25622861943 159983.4215276739 221590.50133633584 171000.85838439074 125921.25447811215 203310.56718853352 162533.18468329817 196694.52669191282 103344.27613832914 173224.3469640263 193475.6570046085 127412.41851523638 263655.3466367899 182948.1289481549 113316.0227092939 261792.52595635882 150234.6986472512 130506.18000860902 202156.69076084785 329561.21975316934 115692.99207727997 132465.46327665407 235433.39731340742 118042.61858292307 349776.7685613655 126657.79592354628 127702.47733565154 116044.98260895633 127057.04836076275 417061.1935362713 134469.1783319008 120903.76606625521 199455.80092578675 110411.86595634441 319656.88189148606 148838.58903237787 243736.22115625278 197799.56755635972 151893.86347723147 136486.29125662506 108288.3765618684 68402.98585330248 162077.79733182193 303060.05494240986 284238.9078950783 291496.79600039835 214906.24514958385 112387.2862762651 324107.82716394344 108936.68099580277 163757.5127918995 125150.80639949614 124252.68275649336 112437.67705439386 84655.9996993055 478874.99190664775 185875.03802954193 314833.1373081232 317769.2763643611 142682.41416181097 117967.7566534251 107681.73455370773 69476.18368625511 118032.88318825007 102688.5302816786 154796.0768508523 130206.62326613606 270431.46916823153 210974.21196573635 140879.50188866624 179606.15649354408 142018.53108267806 145652.44163156647 131176.91646709305 265865.70339923183 105217.63655544737 169958.51061449558 168932.53145485886 169000.77696339544 207776.31681588478 249369.91381035754 165720.97334999708 206897.79199295104 246798.02337506876 141287.7673353944 184321.7899603988 153273.89121828703 152061.2140475169 271086.2094659759 145911.44647819272 176962.18932407425 57037.494679116535 110629.40297189585 136215.9410289983 135132.40913392123 201114.96921568835 117681.32484791096 104839.14605999862 109790.91453664354 124648.89317771484 281097.94926272397 143574.22183480943 142542.16299636473 174587.96763696242 206426.40312599938 183686.6895340356 132658.58918578853 230581.4496118231 111143.63974102792 144727.9068528985 183930.55760926084 186247.4846769694 364433.7599942842 192786.14536801365 112918.45215866725 65582.47946227874 352847.45025483717 388611.8720763874 130934.90551458026 239231.83930336768 484795.7387308299 360573.2530364891 134919.69656834565 171400.98221738578 152614.31194632244 134579.01727463826 131821.02045492013 244788.7578305834 189072.85042941166 124576.69754704583 57338.98576884395 110152.32666015008 147833.28338949315 199225.83280027838 154463.9872292436 86320.26581603984 123513.18433834221 131331.04133623993 144410.4932175223 87078.52409388332 136535.3241092869 192386.01948200076 147884.53813873162 337716.5119432198 139617.42718314801 116470.4150997194 113097.2313954969 219937.09278817743 321859.3001852256 424157.62247926276 231738.5141599473 348060.05198192736 82513.60883472298 100451.01271358962 155795.2997649729 298729.7777180168 127265.40361001863 130552.9895561325 218451.91481251357 124060.04623967435 169432.76220162562 184064.35017208496 96227.5964112766 125090.19313895043 143242.46600784737 262368.0869215741 143611.12751465425 308787.027318569 227398.47689869447 191909.12072116154 86306.96234905752 117236.52832520049 107023.86527870523 141116.82291935995 169061.63154510324 172962.68062023947 165042.14843564518 213646.38442422572 94078.315091583 211073.89779052534 123180.84375306833 229683.67914958534 199520.7659484812 124585.54570678652 326779.4739941102 193264.6380312242 124841.37266061889 252445.00403539673 137709.79246270328 148318.06470864048 113587.94993452747 225421.1653213864 137875.72084905504 106800.85602309763 164418.07502246567 211003.11386732382 276110.73167634767 180975.01618394826 148626.3991561709 123887.56063231542 131989.08941924956 142124.56791005033 213778.26066210362 219400.61679049765 95125.33564912969 214342.2840592098 148771.97489086605 96227.63096448449 104154.98629343866 163196.32175833898 104891.51857985578 104703.88871275811 176824.30117935422 120664.99442245865 127691.98967883115 230589.67677719303 142645.0851371207 200945.2819492841 152654.00561448073 252381.46875912335 124574.14001523581 107535.75230330015 235261.7721813042 207421.19533087028 406760.80259004585 183457.51311486994 126749.23032715016 158495.98554586098 176836.36092148925 140090.7299223903 98984.97129498188 177417.96748840963 170624.4844102903 141184.83967369667 82409.44403162875 143720.2627024783 141941.3507275585 117485.45941125756 117831.79046241501 172953.68433109586 264963.1986821306 289560.57761446404 164458.09097098833 132047.06141247333 242414.3412478341 310012.71188113175 208611.57171903877 176225.89437285042 138918.92926259153 120453.70374362738 170519.58437862594 381627.71698586806 207832.26689500382 237825.95554505484 90570.11313693826 95050.95296781072 138593.1772617261 136016.9094951596 275045.24196814134 209629.63145770092 139560.34695177918 200331.11371126122 86129.80037953035 191058.08728889548 109745.57336793232 325959.08837483235 176361.88661961927 217579.85438489838 126084.47204953429 242799.84098763447 184319.21882034992 113253.18534456854 118892.66863344643 138687.07051608837 181061.871378745 93042.60854889391 152462.13627778893 155644.14521115724 134901.1775193055 175599.43558261075 110902.12245990321 181703.46120183074 232426.68099288418 130087.0262854889 145526.4742915302 166261.22144541488 205112.63886425647 148785.41770553874 204174.38481396995 197245.02895452743 130774.98753006948 149066.4744946961 192290.36385273404 86838.85464819372 170625.82388855933 139996.29616128688 168728.7493829243 187755.80080882955 166018.99618147756 302274.31774717686 92720.56438358189 233693.06087174575 137167.94724473497 132202.2155443083 81245.1505435061 201636.0381415327 159055.94795600243 132500.92885903007 199866.72581119527 153675.5880751207 105343.82732956616 154563.62508018524 152683.10313112388 134246.3047378255 198842.26141169318 165489.05545716413 123152.84130059947 131113.81142522267 93395.76897642556 74528.04901375732 217114.34974870397 186549.62519053006 139330.2864264903 130784.76453304074 176178.99358979295 229968.12515639962 340938.55890678853 359942.23210148804 110112.12081589023 234353.59289616405 124352.12814556056 289672.7592554807 375625.99118962244 289345.51184955385 174829.66877874357 253932.1439679101 142611.43263756364 128220.74080762315 85986.02701781986 212145.23418242467 354580.9025455274 193950.1538519174 139167.56726101672 259356.14754898782 225588.57947548258 133232.15346672927 188615.48944982153 190163.02794213942 107855.30013774312 127372.1873647017 149587.6550989608 124183.39940751695 176706.75140677812 120240.09571413753 186989.7470715744 158230.21091427488 131167.33943835704 227363.03064233653 178930.41124694585 96547.34595189671 216324.5715153015 144029.2859419545 185908.92846184561 187131.3365867163 164616.20718170406 135517.523701403 217510.75658906923 143891.27035962872 109859.41129217812 274395.39358338993 182549.31938827396 119238.51080153615 140657.34233636584 140486.2084739426 327522.88018812233 143997.8413265069 443345.5720728042 133722.01516996117 173673.46620208706 170132.7684650762 133126.54434687053 160611.8237024678 386806.52736267156 117344.0334088499 151886.20673293993 148471.3324944289 99302.3631806411 202923.6049893851 138582.60862042784 225667.6161064137 202572.57743859387 212905.54430421168 207343.23561190302 79415.0474730091 315683.95417242515 151190.1894178075 331934.517280458 124647.44953310242 355798.28495013487 282750.04860052397 125060.31409494304 216732.38789589537 247925.0831369289 202618.9783842293 172537.8010068895 253812.5471773737 114356.0640735794 225784.23617235135 168280.91029742634 198687.6333844726 237103.16094892085 119916.29569793842 148696.11250876696 181175.5639203985 134156.67097726092 120072.85850046604 203244.9517853045 132708.31678154974 463212.03806300554 188086.74925607376
df.to_csv('train1')
from sklearn.linear_model import PassiveAggressiveRegressor
regr = PassiveAggressiveRegressor(max_iter=100, random_state=0,tol=1e-3)
regr.fit(X_train, y_train)
PassiveAggressiveRegressor(max_iter=100, random_state=0)
PassiveAggressiveRegressor(max_iter=100, random_state=0)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
PassiveAggressiveRegressor(max_iter=100, random_state=0)
y_test_pred= regr.predict(X_test)
print( 'r2 score on testing dataset:', r2_score(y_test, y_test_pred))
print( 'MSE on testing dataset:', mean_squared_error(y_test, y_test_pred))
print( 'RMSE on testing dataset:', (mean_squared_error(y_test, y_test_pred)**.5))
print( 'MAE on testing dataset:', mean_absolute_error(y_test, y_test_pred))
r2_test.append(r2_score(y_test, y_test_pred))
MAE_test.append(mean_absolute_error(y_test, y_test_pred))
MSE_test.append(mean_squared_error(y_test, y_test_pred))
RMSE_test.append(mean_squared_error(y_test, y_test_pred)**.5)
r2 score on testing dataset: 0.5396063748255786 MSE on testing dataset: 0.07792915707363604 RMSE on testing dataset: 0.27915794288115114 MAE on testing dataset: 0.16529953679979653
for i in y_test_pred:
print(np.exp(i))
print(len(r2_test))
print(r2_test)
plt.figure(figsize=(10,6))
plt.title('Comparision chart for R2 Score')
plt.xticks(rotation=90)
sns.barplot(x=models,y=r2_test)
<Axes: title={'center': 'Comparision chart for R2 Score'}>
plt.figure(figsize=(10,6))
plt.title('Comparision chart for Mean Absolute Error')
plt.xticks(rotation=90)
sns.barplot(x=models,y=MAE_test)
<Axes: title={'center': 'Comparision chart for Mean Absolute Error'}>
plt.figure(figsize=(10,6))
plt.title('Comparision chart for Mean Squared Error')
plt.xticks(rotation=90)
sns.barplot(x=models,y=MSE_test)
<Axes: title={'center': 'Comparision chart for Mean Squared Error'}>
plt.figure(figsize=(10,6))
plt.title('Comparision chart for Root Mean Squared Error')
plt.xticks(rotation=90)
sns.barplot(x=models,y=RMSE_test)
<Axes: title={'center': 'Comparision chart for Root Mean Squared Error'}>